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)
 Dynamic values in IN clause of condition

Author  Topic 

anandc
Starting Member

20 Posts

Posted - 2006-06-20 : 02:26:37
How do i include values in the IN clause dynamically.

e.g.

DECLARE @showAudit char(1)
SET @showAudit = 'N'
SELECT * FROM tr_CommTrans
WHERE Status IN (CASE WHEN @showAudit = 'N' THEN ('1','2','3')
ELSE Status
END)


Can I write something like the above ??


- Anand

sachinsamuel
Constraint Violating Yak Guru

383 Posts

Posted - 2006-06-20 : 02:38:42
Check out sp_executeSQL and execute in SQL help files.

Regards
Sachin

Don't sit back because of failure. It will come back to check if you still available. -- Binu
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-20 : 02:56:13
[code]DECLARE @showAudit char(1)
SET @showAudit = 'N'
SELECT * FROM tr_CommTrans
WHERE (@showAudit = 'N' and Status in ('1', '2', '3'))
or @showAudit <> 'N'
[/code]


KH

Go to Top of Page

miclare
Starting Member

5 Posts

Posted - 2006-07-02 : 11:03:56
quote:
Originally posted by anandc

How do i include values in the IN clause dynamically.

e.g.

DECLARE @showAudit char(1)
SET @showAudit = 'N'
SELECT * FROM tr_CommTrans
WHERE Status IN (CASE WHEN @showAudit = 'N' THEN ('1','2','3')
ELSE Status
END)


Can I write something like the above ??


- Anand



i've got the same problem. any answer?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-03 : 02:37:44
Did you try the method suggested by khtan?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-03 : 02:43:36
"i've got the same problem. any answer?"
What exactly is your problem ? Can you provide more information ?


KH

Go to Top of Page
   

- Advertisement -