Team I need a help
I sql server I have to daily extract the report from my table Grand_total
I have to get 3 column like this
Only On 27th november 2017 1-22 novmber 2017 1 October to 27 october 2017
500 1000 9999
In first column I want data as on yesterday,2 column I want data as on 1st day of current month till yesterday and
3 column i want data from 1st day of previous month till previous day of previous month(Example suppose today is 28th November so 01-October to 27 October 2017)
I doesn't want to put date everyday and i want to make it schedule automatically
My orderdate is in Varchar(20)...I can change it in Date datatype also but I need in Varchar
How shloud I write the query for that
Note I have written query to split column into 3 part,I need again and again i don't have to pass date.
Any way to write procedure so that it automatically run and i get the data
As data is coming from single table so i used Case if to split in 3 column
SELECT xy as COMPANY,Channel as Channel,regionname ,
**sum(CASE WHEN op.orderdate = '2017-11-27' THEN inna ELSE '0' END) AS SalesToday, **
**sum(CASE WHEN op.orderdate between '2017-11-01' and '2017-11-27' THEN inna ELSE '0' END) AS till_1_to_yesterdaysales, **
**sum(CASE WHEN op.orderdate between '2017-10-01' and '2017-10-27' THEN inna ELSE '0' END) AS till_1_to_yesterdaysales_previousmnth **
from GRAND_TOTAL OP
CHANNEL='10-GENERAL TRADE ' group by xy, CHANNEL,regionname;