Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

String Execution in SQL Expand / Collapse
Author
Message
Posted Thursday, June 26, 2008 9:01 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, August 28, 2008 11:57 PM
Points: 9, Visits: 42
select * from t_system

O/p is
---
AS400
CPS
HBS

But the below code is not work

declare @i varchar(100)
set @i = 'as400,cps'
select * from t_system where systemcode in (@i)

anybody help


I need to implement this one to production db.
Actual problem is, when the client pass 'as400' server will respond only as400 and when the client pass 'CPS' server will respond only 'CPS'


But the client pass the argument 'ALL; server need to return all the above. How to implement anybody plz help!!!!!!!!!!!!!!!!!!!!!!!!!!!
Post #524277
Posted Thursday, June 26, 2008 10:30 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 29, 2014 2:57 AM
Points: 1,098, Visits: 1,222

Try this...

declare @i varchar(100)
set @i = '''as400'',''cps'''
select * from t_system where systemcode in (@i)

Mahesh


MH-09-AM-8694
Post #524384
Posted Thursday, June 26, 2008 11:39 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Monday, November 17, 2014 12:50 PM
Points: 13,872, Visits: 9,598
Mahesh Bote (6/26/2008)

Try this...

declare @i varchar(100)
set @i = '''as400'',''cps'''
select * from t_system where systemcode in (@i)

Mahesh


That won't work. "In" doesn't work that way with variables.

There are a couple of ways you can do this. One is create a table of the system codes and query that as a sub-query or a join. Another is provide a comma-delimited list of system codes, and then query it with a string parser (there are some on the scripts page of this site).



- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #524451
Posted Thursday, June 26, 2008 8:13 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 12:06 PM
Points: 35,572, Visits: 32,164
To wit...

http://www.sqlservercentral.com/articles/T-SQL/63003/


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #524699
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse