SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


group by/date/week/moth/year/product


group by/date/week/moth/year/product

Author
Message
harita
harita
SSC Veteran
SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)SSC Veteran (261 reputation)

Group: General Forum Members
Points: 261 Visits: 188
Hi, all
group by/date/week/moth/year/product
need help with this report and this is the code


SELECT
CT.NAME AS BILL_TO_NAME,
IT.ITEMNAME,
SUM(SL.qtyordered) as quantity,

FROM
[x].[dbo].x SL (NOLOCK)
INNER JOIN
x.[dbo].x ST (NOLOCK)
ON SL.x = ST.x
AND SL.x = ST.x
INNER JOIN
x.[dbo].x CT (NOLOCK)
ON CT.x = ST.x
AND SL.x = CT.x
INNER JOIN
x.[dbo].x IT (NOLOCK)
ON SL.x = IT.x
AND SL.x = IT.x

WHERE IT.x = 'Fluor-A Day 0.50mg Chewable Tablets' AND
--EXCLUDE Returns
ST.x='' AND
--EXCLUDE Sample Orders. Orders for zero dollars
SL.x > '0' --AND SL.Createddatetime between @StartDate and @EndDate
GROUP BY CT.x,IT.x

--dont know if this the right way i am doing--please see the attached image--

Thank you all for looking at it..............
Attachments
1sd.png (9 views, 43.00 KB)
Daniel Bowlin
Daniel Bowlin
SSCarpal Tunnel
SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)SSCarpal Tunnel (4.8K reputation)

Group: General Forum Members
Points: 4822 Visits: 2629
saimddr (10/8/2010)
Hi, all
group by/date/week/moth/year/product
need help with this report and this is the code


SELECT
CT.NAME AS BILL_TO_NAME,
IT.ITEMNAME,
SUM(SL.qtyordered) as quantity,

FROM
[x].[dbo].x SL (NOLOCK)
INNER JOIN
x.[dbo].x ST (NOLOCK)
ON SL.x = ST.x
AND SL.x = ST.x
INNER JOIN
x.[dbo].x CT (NOLOCK)
ON CT.x = ST.x
AND SL.x = CT.x
INNER JOIN
x.[dbo].x IT (NOLOCK)
ON SL.x = IT.x
AND SL.x = IT.x

WHERE IT.x = 'Fluor-A Day 0.50mg Chewable Tablets' AND
--EXCLUDE Returns
ST.x='' AND
--EXCLUDE Sample Orders. Orders for zero dollars
SL.x > '0' --AND SL.Createddatetime between @StartDate and @EndDate
GROUP BY CT.x,IT.x

--dont know if this the right way i am doing--please see the attached image--

Thank you all for looking at it..............

Well the first thing I would do is create a calendar table containing date, week of year, weekendingdate, monthname, monthnumber, quarter (just in case, or for future use) and year. Actually when creating a calendar table I would add a lot more columns, but these will do for you immediate need.

Then join the calendar table to your query and add the date, weekendingdate, monthname and/or monthnumber, and year to your select statement.

The resulting dataset should give you everything you need to build your report. Your picture looks like you probably want to use a matrix report
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search