Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Get results from yesterday if datetime betwen 00:00:00 and 06:00:00

$
0
0
Hello,I'm not sure how to implement this, I have a Sybase DB 15.4 but I guess if I found the logic in SQL I will figure out it in Sybase,What I need to get its the following:I have a table with tickets lets say just 3 columnsTicket number = intTicketDate = DATETIME ( But just have the date)TicketTime = VARCHAR(8) Just have the time in 00:00:00This is a query so I cannot use parameters,So when the user run the query if the user it's running the query between 00:00:00and 06:00:00 then I need to get the results of Yesterday of the tickets with the column TicketDateSomething like Select Ticketnumber, TicketDate, TicketTime From ticket WHERE CASE TicketTime WHEN TicketTime BETWEENSELECT CAST(SUBSTRING(CAST(GETDATE() AS BINARY(8)),1,4) + 0x00000000 AS DATETIME) AND SELECT CAST(SUBSTRING(CAST(GETDATE() AS BINARY(8)),1,4) + 0x00600000 AS DATETIME) THEN TicketDate = GETDATE() or current_date() ELSETicketDate = (Dateadd(dd, -1, GETDATE())But the CASE Will not work in the Where Clause, Any Ideas?Thanks,Regards

Viewing all articles
Browse latest Browse all 3145

Trending Articles