Geeks With Blogs
Pankaj Tahiliani

INSERT INTO hits (recorded_time,ip,ua,request,referer,is_unique)
SELECT Convert(datetime,'2010-02-10 11:00:00'),00001001,'IE','default.aspx','direct',0
WHERE NOT EXISTS (SELECT ID FROM  Hits WHERE IP=00001001);SELECT @@IDENTITY;

Above query will check the existing record of the given IP. If found than it will return the ID else it will insert the new record and than return the newly generated ID.

Posted on Tuesday, February 9, 2010 11:42 PM | Back to top


Comments on this post: Prevent duplicate records using insert query

# re: Prevent duplicate records using insert query
Requesting Gravatar...
Tinmua24h chuyên cung cấp bán buôn sỉ lẻ các loại Loa Vali Kéo hát karaoke của các hãng Temeisheng, Feiyang, MBA, Bock… Các dòng loa quảng cáo, loa bán hàng, truyền thông, loa trợ giảng
Left by Hà Nguyễn on May 31, 2017 3:39 PM

Your comment:
 (will show your gravatar)


Copyright © Pankaj Tahiliani | Powered by: GeeksWithBlogs.net