0

In table Requets, have RequestNo, DTTDay, DMRDay, CombineDay, etc

I want to select the details when :

if CombineDay <> 0
        will select the data when CombineDay < 24
else 
        will select the data when (DTTDay < 24 or DMRDay < 24)

Have tried

select * from Request
where Case when CombineDay <> 0 then 
        CombineDay < 24
      else 
        DTTDay < 24 or DMRDay < 24

But its like something wrong with the query. Appreciate any help. Thanks

ps : have no idea what to put on Title

Edit: Sample Table

RequestNo   BookingNo   DTTDay  DMRDay  CombineDay

SR-xx       Pxx         0       0       14
SR-xx       Pxx         8       0       0
SR-xx       Pxx         0       0       28

Edit: i think my explanation is not very clear. Ok, the sample data above the the original data. From that table, i want to select details where firstly it check if CombineDay <> 0, it will select the detail when CombineDay < 24. And else, it will select the details when (DTTDay < 24 or DMRDay < 24)

Kiki
  • 5
  • 5
  • Please provide a sample table and output OR create a fiddle. – Ullas Aug 27 '14 at 05:43
  • `CASE` is an *expression* - it computes a scalar *value*. It's not a control flow statement. And I'm afraid your explanation isn't very clear - I can see you've added some sample data - so what is the expected *result* when querying against that data? Or if it is, in fact, the expected result, what was the original data in the table? – Damien_The_Unbeliever Aug 27 '14 at 06:14
  • @Ullas - have put the sample table. – Kiki Aug 27 '14 at 06:14
  • And what is `CombineFreeDay` - is that a typo, or is it meant to be some kind of parameter to the query? – Damien_The_Unbeliever Aug 27 '14 at 06:15
  • Have you tried this way? http://stackoverflow.com/questions/87821/sql-if-clause-within-where-clause – Alex Szabo Aug 27 '14 at 06:16

1 Answers1

1
select * from Request where (CombineFreeDay <> 0 and CombineDay < 24)
  or (CombineFreeDay = 0 and (DTTDay < 24 or DMRDay < 24))
Community
  • 1
  • 1
Krystian Lieber
  • 481
  • 3
  • 10
  • can you help me to edit your answer by change the table name to Request since i unintentionally put the original table name before? hope you dont mind. Tqvm – Kiki Aug 27 '14 at 06:39