954,135 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to write this sql statement?

Hi all,

DECLARE @STA as char(50)
SET @STA = 'TT'
SELECT * FROM ABC_TBL where ABC_Filed in (@STA)

if i have multivalue in parameter @STA, like 'TT', 'DD', 'AA'
so how can i write my statement? i only need to pass one parameter with multilist, so do anybody know how to write the MS sql statement?
Example like
DECLARE @STA as char(50)
SET @STA = 'TT', 'DD'
SELECT * FROM ABC_TBL where ABC_Filed in (@STA)

Thank You.

Regards,
S3ng

s3ng
Newbie Poster
1 post since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

How are you building the string before submitting it as the parameter value?

GhostWolf
Newbie Poster
2 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

have a look at the sp_executesql (or is it sp_execute -- can't remember). with this method, you build your string in SQL, then execute it with the SP above. BOL should have more info and examples

MCP
Light Poster
44 posts since Oct 2006
Reputation Points: 14
Solved Threads: 3
 

you want to use dynamic sql

DECLARE @STA as char(50)
SET @STA = '''TT'', ''DD'''

exec ('SELECT * FROM ABC_TBL where ABC_Filed in ('+'@STA')')

campkev
Posting Pro in Training
484 posts since Jul 2005
Reputation Points: 14
Solved Threads: 19
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You