Thursday, March 8, 2012

assign variable within SP

I use SQL Server 2005 and in a Stored Procedure I want to execute a sql statement and assign the result to a variable. How can I do that?
The name of the column I want to retreive the value from is "UserID"
Here's my SP so far:

ALTERPROCEDURE [dbo].[spUnregisterUser]

@.UserCodeint

AS

BEGIN

SETNOCOUNTON;declare @.uiduniqueidentifier--get useridSELECT @.uid=UserIDFROM tblUserDataWHERE UserCode=@.UserCode-- Delete userUPDATE tblUserDataSET IsDeleted='True'WHERE UserCode=@.UserCode

END

That's pretty much how you'd do it. What's not working?

No comments:

Post a Comment