Link to home
Start Free TrialLog in
Avatar of Lorna70
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.SqlError: 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
ASKER CERTIFIED SOLUTION
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lorna70
Lorna70

ASKER

D'oh!  Thank goodness for you guys - you keep me sane ha ha!