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.
| Author |
Topic |
|
wilshaw
Starting Member
10 Posts |
Posted - 2010-09-14 : 16:08:20
|
| Hi, I'm trying to check if a user exists, and if so execute an INSERT, but its not working - can anyone tell me what I'm doing wrong? @UniqueID As Int, @BrowseID As VarChar(100), @IPAddress As VarChar(50), @Username As VarChar(200), @referencetype As VarChar(50), @referencename As VarChar(50)AS If Exists(SELECT * from Users WHERE PersonID = @UniqueID AND UserName = @Username AND BrowseID = @BrowseID And IPAddress = @IPAddress) BEGIN INSERT INTO Referencing (CandidateID, referencetype, referencename)VALUES(@UniqueID, @referencetype, @referencename) END RETURNAny help is appreciated. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-09-14 : 16:41:21
|
looks like your select isn't returning a row and so the condition isn't true.check the values of your parameters! No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
wilshaw
Starting Member
10 Posts |
Posted - 2010-09-14 : 16:59:17
|
| Thanks - I have checked all the values and they are there. I've even broke it down so it only uses 1 parameter each in the select and insert, and it's still not working.I've never used an 'if exists' before and was just wondering if the statement was correct. |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-09-14 : 17:55:38
|
as Fred said, your query isn't returning anything@UniqueID As Int,@BrowseID As VarChar(100),@IPAddress As VarChar(50),@Username As VarChar(200),@referencetype As VarChar(50),@referencename As VarChar(50)ASSELECT * from UsersWHERE PersonID = @UniqueIDAND UserName = @UsernameAND BrowseID = @BrowseIDAnd IPAddress = @IPAddress what does this return? |
 |
|
|
rohitvishwakarma
Posting Yak Master
232 Posts |
Posted - 2010-09-15 : 07:41:48
|
| @WilshawWhat does the above query returns? |
 |
|
|
|
|
|
|
|