Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 combine 2 queries

Author  Topic 

devid3an
Starting Member

2 Posts

Posted - 2013-11-01 : 06:57:32
hey been trying a few different things but not working any help please would be awesome. its 2 separate queries with the same select commands would like this to be in one report, thank you so much

SELECT
POHEAD.DocumentNo
,POHEAD.CreditorCode
,POHEAD.InternalReference
,POHEAD.QuantityOrdered
,POHEAD.Z_ArrivalDate
,POHEAD.Z_ArrivalTime
,POHEAD.Z_CountedDate
,POHEAD.Z_CountedTime
,count(POLINE.ProductCode)
,POHEAD.PostStatus
FROM POHEAD
JOIN POLINE ON POHEAD.DocumentID=POLINE.DocumentID
WHERE POHEAD.Z_ArrivalDate <> '' and POHEAD.Z_CountedDate <> '' and POHEAD.Z_CountedDate >= :fromdate and POHEAD.Z_CountedDate <= :todate
GROUP BY POHEAD.DocumentNo
,POHEAD.CreditorCode
,POHEAD.InternalReference
,POHEAD.QuantityOrdered
,POHEAD.Z_ArrivalDate
,POHEAD.Z_ArrivalTime
,POHEAD.Z_CountedDate
,POHEAD.Z_CountedTime
,POHEAD.PostStatus
ORDER BY POHEAD.Z_CountedDate
,POHEAD.Z_CountedTime


SELECT
POHEAD.DocumentNo
,POHEAD.CreditorCode
,POHEAD.InternalReference
,POHEAD.QuantityOrdered
,POHEAD.Z_ArrivalDate
,POHEAD.Z_ArrivalTime
,POHEAD.Z_CountedDate
,POHEAD.Z_CountedTime
,count(POLINE.ProductCode)
,POHEAD.PostStatus
FROM POHEAD
JOIN POLINE ON POHEAD.DocumentID=POLINE.DocumentID


WHERE POHEAD.Z_ArrivalDate <> '' and POHEAD.Z_CountedDate = '' and POHEAD.PostStatus = 'U' and POHEAD.QuantityReceipted = 0
GROUP BY POHEAD.DocumentNo
,POHEAD.CreditorCode
,POHEAD.InternalReference
,POHEAD.QuantityOrdered
,POHEAD.Z_ArrivalDate
,POHEAD.Z_ArrivalTime
,POHEAD.Z_CountedDate
,POHEAD.Z_CountedTime
,POHEAD.PostStatus
ORDER BY POHEAD.Z_ArrivalDate
,POHEAD.Z_ArrivalTime

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-11-01 : 07:32:50
Qyuery1
union all
Query2

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-01 : 13:20:03
you want to get count values in same row or appear as two rows for each combination?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -