How to write this sql statement?

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2006
Posts: 1
Reputation: s3ng is an unknown quantity at this point 
Solved Threads: 0
s3ng s3ng is offline Offline
Newbie Poster

How to write this sql statement?

 
0
  #1
Dec 14th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2
Reputation: GhostWolf is an unknown quantity at this point 
Solved Threads: 0
GhostWolf GhostWolf is offline Offline
Newbie Poster

Re: How to write this sql statement?

 
0
  #2
Dec 15th, 2006
How are you building the string before submitting it as the parameter value?
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 44
Reputation: MCP is an unknown quantity at this point 
Solved Threads: 3
MCP MCP is offline Offline
Light Poster

Re: How to write this sql statement?

 
0
  #3
Dec 16th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: How to write this sql statement?

 
0
  #4
Dec 20th, 2006
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')')
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC