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
 SQL Server Development (2000)
 case statements in where clause

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-02-04 : 20:05:57
casey writes "I have a table with a date field holding values

200001
200002
200003 ... to current date of 200102

YYYY MM

I'd want to write a stored procedure that selects records for the next month from the previous year:

Ex: if current date is 200101, then I want to select records from 200002.

Is it possible to use a case statement in the where clause for this?

select customer_name, Invoice_number from invoice  
case
when datepart(mm,getdate()) between 1 and 11 then
where fiscal_year = (datepart(yy,getdate()) - 1)
and ( convert(int,substring(accounting_period,5,2)) + 1) = ( datepart(mm,getdate()) + 1)
else
where datepart(mm,getdate()) = 12 then
fiscal_year = datepart(yy,getdate()) and
substring(accounting_period,5,2_ = '01'


Thanks."
   

- Advertisement -