User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 402,008 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,430 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 2530 | Replies: 3
Reply
Join Date: Dec 2006
Posts: 1
Reputation: s3ng is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
s3ng s3ng is offline Offline
Newbie Poster

How to write this sql statement?

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: Jeffersonville, IN, USA
Posts: 2
Reputation: GhostWolf is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
GhostWolf GhostWolf is offline Offline
Newbie Poster

Re: How to write this sql statement?

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

Re: How to write this sql statement?

  #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  
Join Date: Jul 2005
Location: Dallas, TX
Posts: 481
Reputation: campkev is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: How to write this sql statement?

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 9:35 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC