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)
 Case statement in where clause

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2006-05-31 : 11:40:18
I am keep getting an error on Case statemenet in WHERE clause: Incorrect syntax near '<'. I just can't figure out what I am doing wrong... can you help?

select sum(isnull(bad_dept_provision ,0) ) as badp ,a.month,c.region as Region_num,b.region_num as region, b.unit_name ,b.unit_abbr as unit_abbr, a.financial_class_code

FrOM [Revenue_Aggregate_Assertions] a
join Revenue_aggregate b on a.[month] = b.[month] and a.[year] = b.[year] and a.[Unit_abbr] = b.[Unit_abbr] and a.financial_class_code = b.financial_class_code
left join regions c on b.region_num = c.region_num

where ( Case @year when 1 then b.[year] <= year(getdate())
when 2 then b.[year] = year(getdate()) end )
and (@region = 1000 or b.region_num = @region)

group by a.month,c.region, b.unit_name ,c.region, b.region_num ,b.unit_abbr,a.financial_class_code


RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-05-31 : 12:31:10
You probably want something along the lines of...

...
where (@year = 1 and b.[year] <= year(getdate()) or
(@year = 2 and b.[year] = year(getdate()))
...


Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page
   

- Advertisement -