NOT IN + if structure

Hi folks,

I would like to implement the following statement in my report.

AND (CASE WHEN @afwezig ='T'
THEN b.tnr_opname NOT IN
(SELECT tnr_opname
FROM r00aanafw
WHERE datum_van < convert(DateTime,'01/01/2001',103) AND (datum_tot > convert(DateTime,'01/01/2001',103) OR datum_tot is null))

When the parameter equals T, then the field b.tnr_opname shouldn't be in the following select-statement, else there shouldn't happen anything. This code doesn't work. Help me please!

Thx mates

[552 byte] By [woeter] at [2007-12-19]
# 1

I think you have to state a field name first, then the operator, then the case statement. Most of the time I want a different operator, therefor I usually bipass it with ...

If @afwezig = 'T'
Begin
select *
from table
where field = data and b.tnr_opname not in (subquery)
End

If @afwezig <> 'T'
Begin
select *
from table
End

Just another way of doing it...

- Glenda

ggable at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Reporting Services...

SQL Server

Site Classified