Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 howto use IN with a variable

Author  Topic 

stineco
Starting Member

6 Posts

Posted - 2005-06-06 : 11:13:49
Hi am trying to use this

declare @blp1 char(24)
set @blp1 = ('002','003')
select distinct c.opmerking, c.omschrijving, c.em_id
, eq.eq_id, eq.dp_id, eq.bl_id, eq.fl_id
from controle as c
inner join eq on eq.dp_id=c.dp_id
where
c.em_id like 'boon%'
and eq.bl_id in (@blp1)
This isn't working
How can i use the IN statement

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-06-06 : 11:15:38
http://www.sqlteam.com/item.asp?ItemID=11499

Go with the flow & have fun! Else fight the flow
Go to Top of Page

raclede
Posting Yak Master

180 Posts

Posted - 2005-06-06 : 21:09:10
or the easiest way is to use dynamic SQL

declare @blp1 char(24)
declare @sql varchar(1000)
set @blp1 = ('002,003,005')

set @sql = 'select distinct c.opmerking, c.omschrijving, c.em_id
, eq.eq_id, eq.dp_id, eq.bl_id, eq.fl_id
from controle as c
inner join eq on eq.dp_id=c.dp_id
where
c.em_id like 'boon%'
and eq.bl_id in ( ' + @blp1 + ')'

EXEC @sql

"If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year, killing everyone inside. "

raclede
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-06-07 : 07:57:05
Try this i hope this should work for u

declare @blp1 char(24)
set @blp1 = ' ''002'',''003'' '
select distinct c.opmerking, c.omschrijving, c.em_id
, eq.eq_id, eq.dp_id, eq.bl_id, eq.fl_id
from controle as c
inner join eq on eq.dp_id=c.dp_id
where
c.em_id like 'boon%'
and eq.bl_id in (@blp1)


if this will work if ur bl_id is the char or varchar field... for numeric datatype it wont work

Complicated things can be done by simple thinking
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2005-06-07 : 08:24:21
chiragkhabaria, I think you need to read this as well. http://www.sqlteam.com/item.asp?ItemID=11499

Your solution won't work.


Damian
Ita erat quando hic adveni.
Go to Top of Page
   

- Advertisement -