June 26, 2008 at 9:01 am
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!!!!!!!!!!!!!!!!!!!!!!!!!!!
June 26, 2008 at 10:30 am
[font="Verdana"]
Try this...
declare @i varchar(100)
set @i = '''as400'',''cps'''
select * from t_system where systemcode in (@i)
Mahesh
[/font]
MH-09-AM-8694
June 26, 2008 at 11:39 am
Mahesh Bote (6/26/2008)
[font="Verdana"]Try this...
declare @i varchar(100)
set @i = '''as400'',''cps'''
select * from t_system where systemcode in (@i)
Mahesh
[/font]
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
June 26, 2008 at 8:13 pm
To wit...
http://www.sqlservercentral.com/articles/T-SQL/63003/
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply