Union Queries involving 2 Queries
- From: "Zak" <zabedi@xxxxxxxxx>
- Date: 17 Jan 2007 13:01:39 -0800
I've been going through this over and over and I just need another pair
of eyes to look at this before I go nuts!!! I'm trying to combine two
queries so that I can create a crosstab table with names as row
headings, dates as column headings and the sum of the Counts as
Values...
My first query is as follows:
SELECT h.orderdate AS [Date], Count(h.invnumber) AS [Count],
LTrim(RTrim([fname]))+', '+LTrim(RTrim([lname])) AS Name
FROM dbo_npohdr AS h LEFT JOIN dbo_userlist AS u
ON h.origkey = u.userkey
GROUP BY h.orderdate, u.fname, u.lname
ORDER BY h.orderdate;
The second is:
SELECT h.receivedat AS [Date], Count(h.invkey) AS [Count],
LTrim(RTrim([fname]))+', '+LTrim(RTrim([lname])) AS Name
FROM dbo_imhdr AS h LEFT JOIN dbo_userlist AS u ON h.origkey =
u.userkey
GROUP BY h.receivedat, u.fname, u.lname
ORDER BY h.receivedat;
And the third and final one is giving me problems:
SELECT x.date, Sum(x.count) AS SumOfcount, x.name
FROM [select date, count, name
from [qry_Non-PO_Entry_by_Date]
union
select date, count, name
from [qry_PO-Match_by_Date]]. AS x
GROUP BY x.date, x.name;
I'm not sure where I went wrong? Can anyone help???
.
- Follow-Ups:
- Re: Union Queries involving 2 Queries
- From: Marshall Barton
- Re: Union Queries involving 2 Queries
- Prev by Date: Re: Unique key count
- Next by Date: Re: Need help with account rec aging
- Previous by thread: Re: Unique key count
- Next by thread: Re: Union Queries involving 2 Queries
- Index(es):
Relevant Pages
|