Hello ~ Hello
I am trying to get the following Sub-Query to work in SQL Server (Although both queries were brought to SQL from Access)
Both Queries work independantly with the second query derriving its records and field names from the first query
Here is the first query
Code:
SELECT DISTINCT a.ABCID, RprtDate, TimeStmp, LOCNUM, IIf(Left([DISTLABEL],4)='ABCD','ABCD',[DISTLABEL])
AS Section, IIf(Left([DISTLABEL],4)='DOCK','Phone','Fax')
AS Fax, a.BEGINDATE, a.CRADDLEDATE, a.GROUP
FROM dbo.MyTable a
WHERE GROUP IN ('DEFG','ABCD')
Here is the second query which derrives its values from the above query
Code:
SELECT a.RprtDate, a.Section, Count(a.TimeStmp) AS Total, a.TimeStmp
FROM dbo.MyTable a
GROUP BY a.RprtDate, a.Section, a.TimeStmp
And here is my attempt to Nest the first query in the FROM Clause of the second query
Code:
SELECT a.RprtDate, a.Section, Count(a.TimeStmp) AS Total, a.TimeStmp
FROM (SELECT DISTINCT a.[ABCID], RprtDate, TimeStmp, [LOCNUM], IIf(Left([DISTLABEL],4)='ABCD','ABCD',[DISTLABEL])
AS Section, IIf(Left([DISTLABEL],4)='DOCK','Phone','Fax')
AS Fax, a.[BEGINDATE], a.[CRADDLEDATE], a.[GROUP]
FROM dbo.MyTable a
WHERE [GROUP] IN ('DEFG','ABCD')
GROUP BY a.RprtDate, a.Section, a.TimeStmp)
The error I can't seem to get rid of is the: Incorrect syntax near ')' which occurs on the last ')' of the query after TimeStmp in the GROUP Clause
Usually these errors are easy to fix - but this is my first attempt at building a Sub-Query and so, yeah, not having any luck at all making the little red squiggly line go away.
Thanks as always...