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

time series from particular day in month 1 to particular day in month 2

$
0
0
Hi, I need a help with getting dates from day to day in month. Example:I have daily sales fact. Customer wants to compute monthly sales from 2nd in month to 1st in next month and set is as month from start date.January: 2.1.2015 - 1.2.2015February: 2.2.2015 - 1.3.2015etc..Now I can do next:SELECT * FROM FactSales WHERE DateID > datefromparts(year(DateID), month(DateID), 1) AND DateID <= DATEADD(DAY, 1, EOMONTH(DateID,0))but the output alway without 1st in month as i assume my first condition filters it out. Can I do this with group by?select * from factsalesgroup bydatefromparts(year(DateID), month(DateID), 2) , DATEADD(DAY, 1, EOMONTH(DateID,0))but if I want to get dates, I have to group by dateid also and it is not OK, as I am getting wrong dates.Thank you for your helpBorut

Viewing all articles
Browse latest Browse all 3145

Trending Articles