set command error
-
Hi All Iam getting error on executing this procedure Alter procedure LogProc ( @UserId varchar(500), @Password varchar(500) ) as declare @str varchar(500) set @str='select AstId from UserTable where UserId='+@UserId+'and Password='+@Password exec (@str); exec LogProc 'uname','xyz'; Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'Password'.
i want to join this group
-
Hi All Iam getting error on executing this procedure Alter procedure LogProc ( @UserId varchar(500), @Password varchar(500) ) as declare @str varchar(500) set @str='select AstId from UserTable where UserId='+@UserId+'and Password='+@Password exec (@str); exec LogProc 'uname','xyz'; Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'Password'.
i want to join this group
Try something like this:
set @str = ' select AstId from UserTable where UserId = ''' + @UserId + ''' and Password = ''' + @Password + ''''
-
Try something like this:
set @str = ' select AstId from UserTable where UserId = ''' + @UserId + ''' and Password = ''' + @Password + ''''
Hi, Thanks sir.I got It. Veeresh
i want to join this group
-
Hi All Iam getting error on executing this procedure Alter procedure LogProc ( @UserId varchar(500), @Password varchar(500) ) as declare @str varchar(500) set @str='select AstId from UserTable where UserId='+@UserId+'and Password='+@Password exec (@str); exec LogProc 'uname','xyz'; Server: Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'Password'.
i want to join this group
veereshIndia wrote:
set @str='select AstId from UserTable where UserId='+@UserId+'and Password='+@Password exec (@str);
:confused: You can eliminate 'Set' and 'exec (@str)' statements by having the select query alone which will get the records of the appropriate user.
select AstID from userTable where userid = @userid and password = @password
-
Hi, Thanks sir.I got It. Veeresh
i want to join this group
Hi Sir, Once again iam getting this error.Iam very new to Sql .Can please tel me how to use single quotes in query.Also giv me some help to this query Alter procedure LogProc ( @UserId varchar(500), @Password varchar(500) ) as declare @str1 varchar(500) declare @str2 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); exec LogProc 'veeresh','veeresh' Iam getting this error (1 row(s) affected) Server: Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'select'.
i want to join this group
-
Hi Sir, Once again iam getting this error.Iam very new to Sql .Can please tel me how to use single quotes in query.Also giv me some help to this query Alter procedure LogProc ( @UserId varchar(500), @Password varchar(500) ) as declare @str1 varchar(500) declare @str2 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); exec LogProc 'veeresh','veeresh' Iam getting this error (1 row(s) affected) Server: Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'select'.
i want to join this group
Try the query within a bracket () while assigning it with set keyword. i am not sure try it.