Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 value with '

Author  Topic 

PeterG
Posting Yak Master

156 Posts

Posted - 2002-12-18 : 12:24:52
I am doing this in my SP:
IF EXISTS(SELECT 'True' FROM MyTable WHERE username = @username)
return 1
else
..do an insert

The problem is when @username is something like "O'Brien", the query returns 2 although the name exists in the table. I do a Replace(username,"'","''") in my asp before I pass the username param to the SP. So what happens is I end up inserting O'Brien more than once when what I'm trying to do is avoid duplicate names in the table.

How do I fix this so that my SP returns a 1 and not do an insert when O'Brien is passed to it?


PeterG
Posting Yak Master

156 Posts

Posted - 2002-12-18 : 12:39:05
Correction...
when I run the SP with O'Brien, I end up inserting a duplicate record and not 2 as previously stated.

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-12-18 : 12:50:39
If you have the name in a parameter then you don't need to do the replace. That is only if you are using dynamic/embedded sql.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -