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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2001-06-17 : 19:04:25
|
Bobby writes "How can I turn this If..Then..Else Statement into and SQL Select Case statement.
If time()>=#6:00:00 AM# and Time()< #2:30:00 PM# Then TieShift = "1" Else If (Time()>=#2:30:00 PM# and Time() < #11:00:00 PM#) Then TieShift = "2" Else TieShift = "3" End If
I've tried adding it into my code like this:
"SELECT CASE WHEN TieShift = 'time()>=#6:00:00 AM# and Time()< #2:30:00 PM# Then '1' WHEN TieShift = '(Time()>=#2:30:00 PM# and Time() < #11:00:00 PM#) Then '2' ELSE '3' FROM tbl_TieIn"
But It didn't work. I want to retrieve records from my database by shift 1,2, or 3 depending on the time of day.
Here's what it looks when Access converts it (this query does work):
SELECT tbl_Tie.TieShift, tbl_Tie.TieDate, tbl_Tie.TieTime, tbl_Tie.TieAirplane, tbl_Tie.TieInDescription, tbl_Tie.CustVarNo, tbl_Tie.Airline, tbl_Tie.Stall, tbl_Tie.WhosPlane FROM tbl_Tie WHERE (((tbl_Tie.TieShift)=IIf(Time()>=#12/30/1899 6:0:0# And Time()<#12/30/1899 14:30:0#,"1",IIf(Time()>=#12/30/1899 14:30:0# And Time()<#12/30/1899 23:0:0#,"2","3"))) AND ((tbl_Tie.TieDate)=Date())) ORDER BY tbl_Tie.TieShift, tbl_Tie.TieAirplane;
Any help would be useful" |
|
|
|
|
|
|
|