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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with conditional selections.

Status
Not open for further replies.

AmunRa

Technical User
Aug 14, 2003
9
0
0
GB
I have a table with fields called F3,F4,F5,F6,F7,F8,F9,F10.

I want to conditionalyy select these fields i.e.

If todays date is between 1/1/2003 and 30/4/2003 then select F3,F4,F5
Else if it is betwwen 1/5/2003 and 30/9/2003 then
select F6,F7,F8
Else select F9,F10.

Can anybody help with the syntax to do this please.
 
SELECT
'Result1' =
case
when getdate() between '2003-01-01' and '2003-09-30'
then F3
when getdate() between '2003-05-01' and '2003-09-30'
then F6
else F9
end,
'Result2' =
case
when getdate() between '2003-01-01' and '2003-09-30'
then F4
when getdate() between '2003-05-01' and '2003-09-30'
then F7
else F10
end,
'Result3' =
case
when getdate() between '2003-01-01' and '2003-09-30'
then F5
when getdate() between '2003-05-01' and '2003-09-30'
then F8
end
FROM table
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top