Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change where clause upon some condition in a single select statement

Status
Not open for further replies.

itsmeyogi

Programmer
Sep 18, 2000
6
IN
Hi
I have a problem where i want to change the select statement where clause upon a condition

declare @finyr int
select @finyr = 2002
select acct_no
from acct_mast
where case when month(deposit_dt) > 3
then (year(deposit_dt) + 1) >= @finyr
else year(deposit_dt) >= @finyr
end
This query doesn't work !!!!!!!

Thanx in advance!!!!
 
In order for the WHERE clause to work, yo must name a column and then define the criteria using the CASE statement. The following should work.

where year(deposit_dt) >=
case
when month(deposit_dt) > 3
then @finyr-1
else @finyr
end
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top