You can do one of the following:
Edit:
SET @UserId = 0 to SELECT @UserId
This will return the value just like your second part of the IF statement.
Or, seeing that @UserId is set to Output, change:
SELECT SCOPE_IDENTITY() to SET @UserId = SCOPE_IDENTITY()
It depends on how you want to access the data after that. If you want the value to be in your result set, use SELECT . If after that you want to get the new value of @UserId parameter, use SET @UserId
Seeing that you accept the second condition as correct, a query that you could write (without having to change anything outside of this query):
@EmailAddress varchar(200), @NickName varchar(100), @Password varchar(150), @Sex varchar(50), @Age int, @EmailUpdates int, @UserId int OUTPUT IF (SELECT COUNT(UserId) FROM RegUsers WHERE EmailAddress = @EmailAddress) > 0 BEGIN SELECT 0 END ELSE BEGIN INSERT INTO RegUsers (EmailAddress,NickName,PassWord,Sex,Age,EmailUpdates) VALUES (@EmailAddress,@NickName,@Password,@Sex,@Age,@EmailUpdates) SELECT SCOPE_IDENTITY() END END
Curt
source share