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)
2 2707
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?
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)?
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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,...
|
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...
|
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...
| |