Lorna70
asked on
Trying to build a SQL query by passing a string parameter to an sproc
Hi I have the following procedure where I pass in a string for part of the SELECT statement
An example of the @orParams string is:
"ID = 1 OR ID = 3 OR ID = 9"
However, my syntax must be wrong because I'm getting the error:
Error: System.Data.SqlClient.SqlE rror: Incorrect syntax near '='.
Please can someone tell me what's wrong with my sproc below (never done this before ):
PROCEDURE dbo.spSkillsLookUP
/* Input Parameters */
(@orParams nvarchar(4000))
AS
Set NoCount ON
/* Variable Declaration */
Declare @SQLQuery AS NVarchar(4000)
/* Build the Transact-SQL String with the input parameters */
set @SQLQuery = 'SELECT Prof_Desc FROM tblSkills WHERE' + @orParams
Execute sp_Executesql @SQLQuery
An example of the @orParams string is:
"ID = 1 OR ID = 3 OR ID = 9"
However, my syntax must be wrong because I'm getting the error:
Error: System.Data.SqlClient.SqlE
Please can someone tell me what's wrong with my sproc below (never done this before ):
PROCEDURE dbo.spSkillsLookUP
/* Input Parameters */
(@orParams nvarchar(4000))
AS
Set NoCount ON
/* Variable Declaration */
Declare @SQLQuery AS NVarchar(4000)
/* Build the Transact-SQL String with the input parameters */
set @SQLQuery = 'SELECT Prof_Desc FROM tblSkills WHERE' + @orParams
Execute sp_Executesql @SQLQuery
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER