March 25, 2011 at 6:45 am
Hi,
i have date field and product field now i want result in following format
Can anyone provide me sql query for same?
Note : D = DAY
W = WEEK
M = Month
P1 = product1.....
PeriodP1P2
0D157
1D1115
2D67
3D1011
4D49
5D46
6D38
2W1616
3W35
4W1
5W
2M7
3M12
4M1
5M134
<Total>8798
Thanks in advance
March 25, 2011 at 6:58 am
Hi,
There's nowhere near enough information for anyone to help you with this other than it looks like maybe you need to know about the DATEDIFF funtion and PIVOT (both of which can be looked up in BOL).
If you want more in depth advice and some sample code, you'll need to put some effort into explaining your data and the logic behind your required output.
Have a look here for more details:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
March 25, 2011 at 10:16 pm
Thanks for reply guys
my select statement like
select order-id,order date,product name from orders
Basically i need like date hierarchy, when i pass startdate and enddate
day1=start date then from startdate to seven day like day after that i want in week wise total product
one month have max 5 weeks so after that i need month wise data
I hope you guys can understand my requirement.
for eg. i have three different products
so i need a query that give me result set like
period p1 p2 p3
day1 10 5 4
day2 4 3 2
....
day7
week2
week3
........
Month2
........
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply