My guess would be that because the first SELECT is part on the condition, IF NOT EXISTS(SELECT...), it doesn't return a result set. Move the SELECT out of the condition and do some different logic.
Adrian -----Original Message----- From: Russ [mailto:[EMAIL PROTECTED] Sent: 17 February 2006 00:37 To: CF-Talk Subject: if not exists (SQL) question I have a query similar to the following: declare @emailLinkID int if not exists ( select emailLinkID from emailLinks where linkURL='https://www.someurl.com' ) begin insert into emailLinks ( linkURL ) values ( 'https://www.someurl.com, ) set @emailLinkID = @@IDENTITY select @emailLinkID as emailLinkID end This works fine when the record doesn't exist. But it doesn't return the id if the record does exist. What am I doing wrong? Russ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Message: http://www.houseoffusion.com/lists.cfm/link=i:4:232655 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

