Hi,
I'm trying to write a SELECT statement for use in Crystal Reports 8.5, reporting on some tables from Great Plains. I need to access the exact same fields in two Posted Documents tables, and two Unposted Documents tables, and I'm told that UNION is the way to achieve this. But I'm having some trouble. Sorry if my questions are obvious; I haven't had to write much in SQL before.
I'm saying:
SELECT
UnpostedHDR.CustNum, UnpostedHDR.InvNum, UnpostedLINE.ItemNum
FROM
UnpostedHDR inner join UnpostedLINE on UnpostedHDR.InvNum = UnpostedLINE.InvNum
UNION
SELECT
PostedHDR.CustNum, PostedHDR.InvNum, PostedLINE.ItemNum
FROM
PostedHDR inner join PostedLINE on PostedHDR.InvNum = PostedLINE.InvNum
(my syntax may be a little screwy in the example but the query does work except ….)
This query returns all the posted docs, and none of the unposted docs. Now I just tried flipping the query (identical except that I put the Select statement for the Posted first, then UNION, then the Select for the Unposted) - - and it returned only all the Unposted.
My question is two-fold actually: why isn't this working to bring back Posted and Unposted, and further – what I really want to do when I get the UNION working is group all this info by Customer. Customer# exists on each of these tables, but a more detailed Customer table will need to be joined in. Will I use it as part of this UNION statement or separate from it?
What I'm trying to end up with is a list, grouped by Customer, with some fields from the Customer table, and all the items the Customer had purchased, posted and unposted.
Thanks in advance,
Caro
I'm trying to write a SELECT statement for use in Crystal Reports 8.5, reporting on some tables from Great Plains. I need to access the exact same fields in two Posted Documents tables, and two Unposted Documents tables, and I'm told that UNION is the way to achieve this. But I'm having some trouble. Sorry if my questions are obvious; I haven't had to write much in SQL before.
I'm saying:
SELECT
UnpostedHDR.CustNum, UnpostedHDR.InvNum, UnpostedLINE.ItemNum
FROM
UnpostedHDR inner join UnpostedLINE on UnpostedHDR.InvNum = UnpostedLINE.InvNum
UNION
SELECT
PostedHDR.CustNum, PostedHDR.InvNum, PostedLINE.ItemNum
FROM
PostedHDR inner join PostedLINE on PostedHDR.InvNum = PostedLINE.InvNum
(my syntax may be a little screwy in the example but the query does work except ….)
This query returns all the posted docs, and none of the unposted docs. Now I just tried flipping the query (identical except that I put the Select statement for the Posted first, then UNION, then the Select for the Unposted) - - and it returned only all the Unposted.
My question is two-fold actually: why isn't this working to bring back Posted and Unposted, and further – what I really want to do when I get the UNION working is group all this info by Customer. Customer# exists on each of these tables, but a more detailed Customer table will need to be joined in. Will I use it as part of this UNION statement or separate from it?
What I'm trying to end up with is a list, grouped by Customer, with some fields from the Customer table, and all the items the Customer had purchased, posted and unposted.
Thanks in advance,
Caro