[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Trying to build a SQL query by passing a string parameter to an sproc

Posted on 2012-09-13
3
Medium Priority
?
383 Views
Last Modified: 2012-09-19
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
0
Comment
Question by:Lorna70
3 Comments
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 680 total points
ID: 38394193
Change this:

set @SQLQuery = 'SELECT Prof_Desc FROM tblSkills WHERE' + @orParams

To

set @SQLQuery = 'SELECT Prof_Desc FROM tblSkills WHERE ' + @orParams
0
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya earned 320 total points
ID: 38394198
You need a space between where and your params

set @SQLQuery = 'SELECT Prof_Desc FROM tblSkills WHERE ' + @orParams

or to be sure

set @SQLQuery = 'SELECT Prof_Desc FROM tblSkills WHERE' + '  ' + @orParams
0
 

Author Comment

by:Lorna70
ID: 38394638
D'oh!  Thank goodness for you guys - you keep me sane ha ha!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question