473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Union or Join or or

7
Hello,

I am trying to join these two sql statments. I get the following error msg - Incorrect syntax near the keyword 'WHERE'. These statments work Independenantaly without the derived “AS T1” bit.

Can anyone help me to get this to work ?


SELECT DateAdd(Month, DateDiff(Month, 0, Event_Date), 0) AS [Event_Month],
COUNT(*) AS Total_Logged
FROM ([BE].[dbo].[SOE$]
WHERE Team = 'DS'
GROUP BY DateAdd(Month, DateDiff(Month, 0, Event_Date), 0)
ORDER BY [Event_Month]) AS T1

UNION

Select COUNT(*) AS Total_mailed
From ([BE].[dbo].[SOE$]
WHERE Team = 'DS'
AND Action like '%Mail%'
AND Action not like '%Call%') AS T2
GROUP BY DateAdd(Month, DateDiff(Month, 0, Event_Date), 0)
Order BY DateAdd(Month, DateDiff(Month, 0, Event_Date), 0)
Sep 13 '06 #1
2 2707
ttgirl
1
I don't think UNION is the right command for what you're trying to accomplish. Can you provide some sample data and desired results so we can tell what you're trying to achieve?
Sep 13 '06 #2
bhanab
7
Hello ttgirl,

Tx for your reply. I managed to get it to work like this.


Select a.[Date], a.Totalpermonth, b.Totalpermonth
From (SELECT DateAdd(Month, DateDiff(Month, 0, Event_Date), 0) AS [Date],
COUNT(*) AS Totalpermonth
FROM [BE].[dbo].[SOE$]
WHERE Team = 'DS'
GROUP BY DateAdd(Month, DateDiff(Month, 0, Event_Date), 0)
) a, (SELECT DateAdd(Month, DateDiff(Month, 0, Event_Date), 0) AS [Date],
COUNT(*) AS Totalpermonth
FROM [BE].[dbo].[SOE$]
WHERE Team = 'DS'
And Action like '%Mail%'
AND Action not like '%Call%'
GROUP BY DateAdd(Month, DateDiff(Month, 0, Event_Date), 0)
) b
Where a.[Date] = b.[Date]
Order by date

The desired results:

Date Totalpermonth Totalpermonth
----------------------- ------------- -------------
2006-07-01 4650 3330
2006-08-01 3785 2684


I just have to fix up the names.
Sep 14 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Tomas | last post by:
I would like to know if and how it is possible to join the *result* of a union with another table (without first doing individual joins to each part of the result that then will be combined into a...
1
by: dmb000006 | last post by:
My question is about a UNION query to deal with an (annoying) JOIN over two tables. I am joining over a double column primary key (where the order of the columns can be changed). This is sooo...
3
by: Matias Silva | last post by:
Hi Everyone, I wrote a for loop to build several select statements that are combined with a UNION. When I execute one of the queries separately, it works, but when I execute the query with a UNION...
1
by: jtwright | last post by:
I've got a view that creates a parent child relationship, this view is used in Analysis Services to create a dimension in a datastore. This query tends to deadlock after about 10 days of running...
4
by: robert | last post by:
before i go flapping my gums and get deeper in alligators, wondering whether the following makes sense. i have a database which provides picklists for input. it started out with a 2 column key...
3
by: Mike Fellows | last post by:
Help, im trying to use a union join from an SQL database and a Access database - the program works fine from my own machine as i have the odbc DSN connections setup from access to link to the...
7
by: jason.langdale | last post by:
I have 3 tables I want to use in a view. Table A has field 1,2,3,4,5 and table B has field 1,2,3,4,5. I want to do a union on these. (I have done so successfully if I stop here) I also want to join...
4
by: janko.klemensek | last post by:
Can I Group by the Union in one query or must I write two queries for this (one for union and second for group by)?
27
by: MLH | last post by:
How can I turn the following into a make-table query? SELECT & " " & AS Recipient FROM tblVehicleJobs INNER JOIN tblAddnlOwnrs ON tblVehicleJobs.VehicleJobID = tblAddnlOwnrs.VehicleJobID WHERE...
5
zachster17
by: zachster17 | last post by:
Hi everyone, First of all, sorry for the massive amount of SQL I am about to type. I have a database that has a "lives" table of insured employees and then another table (that links to the lives...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.