August 5, 2008 at 12:26 am
declare @errorcode varchar(500)
select @errorcode = reason_code from blr1 where p_id = 236
select p_id,ID,User_ID,cd,cid,k_id,NAM,S_DT,DT,
time,amt,stat,msg,ino,info from pay
where res_msg in(@errorcode)and id ='123'
if i enter ('8','08','18') it gives me the output
as the data in the table is this form
but if i enter (8,08,18) it does not show any data...
....i want tht if i enter (8,08,18) i shud get the data
August 5, 2008 at 2:39 am
maruf24 (8/5/2008)
declare @errorcode varchar(500)select @errorcode = reason_code from blr1 where p_id = 236
select p_id,ID,User_ID,cd,cid,k_id,NAM,S_DT,DT,
time,amt,stat,msg,ino,info from pay
where res_msg in(@errorcode)and id ='123'
if i enter ('8','08','18') it gives me the output
as the data in the table is this form
but if i enter (8,08,18) it does not show any data...
....i want tht if i enter (8,08,18) i shud get the data
Personally I'd be surprised if even the above would work. The in(@errorcode) will check whether the expression on the left hand side matches the whole content of the @errorcode string. I.e. if the @errorcode is '8' it will match '8', but if the @errorcode value is '1,2,3' then it will match '1,2,3' and not 1 or 2 or 3. Somehow I suspect this may not have been your original intention.
You can declare a temp table variable and do a join with it to achieve the above.
e.g.
declare @t table (errocode int)
insert into @t values (8)
insert into @t values (18)
select .... join @t as t on ...=@t.errorcode
if you insist on using "in" you will need to use dynamic SQL.
Another thing is that you mention you would like to use "(8,08,18)". If you have integers (as the numbers here are not surrounded by apostrophes, the 08 will be turned into 8. If you need the preceeding 0s, then you need to sue strings (varchar,. ..)
Regards,
Andras
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply