943,829 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 4709
  • MS SQL RSS
Dec 14th, 2006
0

How to write this sql statement?

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
s3ng is offline Offline
1 posts
since Dec 2006
Dec 15th, 2006
0

Re: How to write this sql statement?

How are you building the string before submitting it as the parameter value?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
GhostWolf is offline Offline
2 posts
since Dec 2006
Dec 16th, 2006
0

Re: How to write this sql statement?

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
Reputation Points: 14
Solved Threads: 3
Light Poster
MCP is offline Offline
44 posts
since Sep 2006
Dec 20th, 2006
0

Re: How to write this sql statement?

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')')
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Active Users in MSSQL
Next Thread in MS SQL Forum Timeline: SQL DB Connection Problems





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC