Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help creating Summary Query
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00712884
Message ID:
00713011
Views:
14
This message has been marked as the solution to the initial question of the thread.
Try to use your detail query as a derived table.
SELECT		det.procid, det.description, 
		det.invid, det.primedesc, 
		det.plannedqty,
		det.actualqty, 
		(det.actualqty - det.plannedqty) as Diff, 
		(det.actualqty*100 / det.plannedqty) as Prc 
FROM (SELECT  	dbo.meetings.begintime, dbo.meetproc.procid, dbo.meetproc.description, 
		dbo.coinv.primedesc, dbo.cocasedata.plannedqty,
                dbo.cocasedata.actualqty, dbo.coinv.invid
FROM dbo.meetings INNER JOIN
     dbo.meetproc ON dbo.meetings.meetingnumber = dbo.meetproc.meetingnumber INNER JOIN
     dbo.cocasedata ON dbo.meetings.meetingnumber = dbo.cocasedata.meetingnumber INNER JOIN
     dbo.coinv ON dbo.cocasedata.linkedid = dbo.coinv.invid
WHERE  (dbo.meetproc.coperid = 189) 
  AND (dbo.meetings.begintime BETWEEN '10/01/2002 00:00:01' AND '10/04/2002 23:59:00')
ORDER BY dbo.coinv.invid ) Det
GROUP BY det.procid, det.invid
>I am trying to create a query to return summary information. Below is the basic query to get the details:
>
>
>SELECT TOP 100 PERCENT dbo.meetings.begintime, dbo.meetproc.procid, 
>       dbo.meetproc.description, dbo.coinv.primedesc, dbo.cocasedata.plannedqty,
>dbo.cocasedata.actualqty, dbo.coinv.invid
>FROM dbo.meetings INNER JOIN
>     dbo.meetproc ON dbo.meetings.meetingnumber = dbo.meetproc.meetingnumber INNER JOIN
>     dbo.cocasedata ON dbo.meetings.meetingnumber = dbo.cocasedata.meetingnumber INNER JOIN
>     dbo.coinv ON dbo.cocasedata.linkedid = dbo.coinv.invid
>WHERE  (dbo.meetproc.coperid = 189)
   AND (dbo.meetings.begintime BETWEEN '10/01/2002 00:00:01' AND '10/04/2002 23:59:00')
>ORDER BY dbo.coinv.invid
>
>OUTPUT (Partial)
>Date/Time               Procid ProcDesc           ITEM DESC                       plnned  Actual   InvID
>2002-10-01 08:00:00.000 7141   CHOLE (POSS OPEN)  SUTURE CL831 (POLYSORB GS-22)     1     4        26161
>2002-10-01 10:30:00.000 7141   CHOLE (POSS OPEN)  SUTURE CL831 (POLYSORB GS-22)     1     1        26161
>2002-10-01 12:00:00.000 7141   CHOLE (POSS OPEN)  SUTURE CL831 (POLYSORB GS-22)     1     1        26161
>
>
>
>So the output I'm hoping to get would return
>By Procedure, By invID, the average variance between the planned qty and actual qty as both a number and percentage.
>
>If anyone can help me with this I'd greatly appreciate it.
>
>Kirk
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform