July 14, 2015 at 3:32 am
I have a problem that requires me to write Daily sum aggregation script, I wrote the script; But what I'm not sure of is the "Daily" part, my script will give me only give me results when I execute it.
Can you help me on how to make this code daily?
SELECT
Receipt
,"Date"
,Item
,Reason
,Division
,SUM(Cost) AS Cost
FROM Cost
WHERE Item IN ('Z001', 'Z002')
GROUP BY
Receipt
,Date
,Item
,Reason
,Division
July 14, 2015 at 3:41 am
Scripts will only give you results when you run them.
What do you mean by 'daily'?
It has to run every day?
It has to return only one day's results?
It has to aggregate by day?
Something else?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
July 14, 2015 at 3:52 am
It has to return only one day's results.
however on that note of your question, how will can it aggregate daily, because I think the code as it is when it runs it will aggregate.
July 14, 2015 at 4:14 am
Depending what your data looks like and what data types are involved, that query could aggregate to the day, to the minute or to the millisecond. Can't tell.
To return only one day's data you need a where clause and a predicate on the Date column. Of what form depends on data types.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply