Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 06, 2012 08:16 PM by JAYHAWKER
Participant
1252 Points
1896 Posts
Apr 06, 2012 08:05 PM|LINK
I don't get an error creating the following procedure, but when I use it with variables, I get the error
Error: Sys.WebForms.PageRequestManagerServerErrorException: Incorrect syntax near '='.
Create PROCEDURE [dbo].[VariableSelect] ( @TableName varchar(50), @AssetID varchar(50) ) as begin declare @sql nvarchar(max) set @sql = 'select * from ' + @TableName + 'Where (etID = ' + @etID + ')' exec sp_executesql @sql end
All-Star
117340 Points
8005 Posts
Moderator
MVP
Apr 06, 2012 08:14 PM|LINK
You need a space before Where and matching parameter name:
set @sql = 'select * from ' + @TableName + ' Where (etID = ' + @AssetID + ')'
Apr 06, 2012 08:16 PM|LINK
Thanks!
JAYHAWKER
Participant
1252 Points
1896 Posts
What is wrong with teh folloiwng stored procedure
Apr 06, 2012 08:05 PM|LINK
Create PROCEDURE [dbo].[VariableSelect] ( @TableName varchar(50), @AssetID varchar(50) ) as begin declare @sql nvarchar(max) set @sql = 'select * from ' + @TableName + 'Where (etID = ' + @etID + ')' exec sp_executesql @sql endlimno
All-Star
117340 Points
8005 Posts
Moderator
MVP
Re: What is wrong with teh folloiwng stored procedure
Apr 06, 2012 08:14 PM|LINK
You need a space before Where and matching parameter name:
set @sql = 'select * from ' + @TableName + ' Where (etID = ' + @AssetID + ')'
Format your SQL query with instant sql formatter:
http://www.dpriver.com/pp/sqlformat.htm
JAYHAWKER
Participant
1252 Points
1896 Posts
Re: What is wrong with teh folloiwng stored procedure
Apr 06, 2012 08:16 PM|LINK
Thanks!