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.

 All Forums
 General SQL Server Forums
 Script Library
 Query to run SQL Query automatically @ 12.00am

Author  Topic 

anuraag205
Yak Posting Veteran

58 Posts

Posted - 2013-02-28 : 04:57:25
I need to write a sql query which should run end of every month and send a excel report. Is this possible in scheduling??

here is the sample query:
====================================================================
SELECT
DATENAME(day,bookDate) as day, DATENAME(Month,BookDate) as Month,
COUNT(Invoice) AS [Total Bookings],
cast (Sum(Negotiated) as decimal (22,2)) AS [Total Sale Price],introducer

FROM tblInvoice
WHERE BookDate >= '2001-01-01'
AND BookDate <= '2020-01-01'



GROUP BY DATENAME(Month,BookDate) , DATENAME(day,BookDate),introducer,
DATEPART(MM,BookDate),DATEPART(dd,BookDate)
ORDER BY DATEPART(dd,BookDate),DATEPART(MM,BookDate),introducer
+============================================================

Thanks in Advance..





Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-28 : 06:34:12
its possible. Create query, add it as a SQL Server agent job step and schedule job to execute every month once at last date.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -