I have a server that contains a column with date only(datetime) and the other with time only(char), but I'm trying to create hourly counts with the code below but it's not showing up as expected:
SELECT
account_date as Date,
sum(qty) as qty
sum(amount) as Amount,
cast(datepart(hour,time) as varchar)
FROM [data source]
WHERE account_date between '10/1/2022' and '10/5/2022'
GROUP BY account_date, time
I'm expecting something like this:
Here's the data format for date and time columns:
**Date**
2022-10-01 00:00:00.000
2022-10-02 00:00:00.000
2022-10-03 00:00:00.000
2022-10-04 00:00:00.000
**Time**
0709
0707
0707
0707
You're looking for a conditional aggregation or a PIVOT.