How to store result of a query in a variable
-
Hi All, Please tel me how to store result of a query in a variable. And I want to use that variable in another query's in where condition Here below is my code. alter procedure LogProc ( @UserId varchar(500), @Password varchar(500) ) as Begin declare @str1 varchar(500) declare @str2 varchar(500) declare @str3 varchar(500) set @str1 =( ' select AstId from UserTable where UserId = ''' + @UserId + ''' and Password = ''' + @Password + '''' ) exec(@str1); set @str2=(' select RoleID from AstProf where AstId = ''''' + @str1 + '''''') exec(@str2); End exec LogProc 'veeresh','veeresh'
i want to join this group
-
Hi All, Please tel me how to store result of a query in a variable. And I want to use that variable in another query's in where condition Here below is my code. alter procedure LogProc ( @UserId varchar(500), @Password varchar(500) ) as Begin declare @str1 varchar(500) declare @str2 varchar(500) declare @str3 varchar(500) set @str1 =( ' select AstId from UserTable where UserId = ''' + @UserId + ''' and Password = ''' + @Password + '''' ) exec(@str1); set @str2=(' select RoleID from AstProf where AstId = ''''' + @str1 + '''''') exec(@str2); End exec LogProc 'veeresh','veeresh'
i want to join this group
Hi, you can store result of the query into a variable like this; select @str1=AstId from UserTable where UserId=@UserId and Password=@Password Here @str1 will store the AstID in it. the complete procedure will liook like this: alter procedure LogProc ( @UserId varchar(500), @Password varchar(500), @str1 int output, @str2 int output ) as Begin declare @str3 varchar(500) /* why u hav declare this variable ???? */ select @str1=AstId from UserTable where UserId @UserId and Password = @Password select @str2=RoleID from AstProf where AstId =@str1 select @str1,@str2 End exec LogProc 'veeresh','veeresh' you may use @str1 and @str2 in your code .
________________ Tehmina Qureshi ****************
-
Hi, you can store result of the query into a variable like this; select @str1=AstId from UserTable where UserId=@UserId and Password=@Password Here @str1 will store the AstID in it. the complete procedure will liook like this: alter procedure LogProc ( @UserId varchar(500), @Password varchar(500), @str1 int output, @str2 int output ) as Begin declare @str3 varchar(500) /* why u hav declare this variable ???? */ select @str1=AstId from UserTable where UserId @UserId and Password = @Password select @str2=RoleID from AstProf where AstId =@str1 select @str1,@str2 End exec LogProc 'veeresh','veeresh' you may use @str1 and @str2 in your code .
________________ Tehmina Qureshi ****************
Hi Sir, Thanks for helping me.I got it. Veeresh
i want to join this group