Hi everyone,
I work at a hospital and I need to aggregate data into months
I am trying to Group some data by a month and year function, the code is below
However the database wont let me, it keeps telling me I need to name my coloums, Ive tried doing this about 10 different ways with no luck eg:
ORDER BY
a.SCV_DATE or
Month or
{fn MONTHNAME(a.SCV_DATE)} AS Month
Has anyone got any ideas, I will be eternally grateful
SELECT
c.SUR_NAME,
{fn MONTHNAME(a.SCV_DATE)} AS Month,
{fn YEAR(a.SCV_DATE)} As Year,
COUNT(*),
COUNT(*)
FROM
odbc.dbo.PATIENT d,
odbc.dbo.SESSION b,
odbc.dbo.SURGEON c,
odbc.dbo.SESCORVU a
WHERE
c.SUR_TYPE = "C" AND
a.SCV_DATE = d.PAT_DATE AND
a.SCV_SESSNO = d.PAT_SESSNO AND
a.SCV_THEATRE = d.PAT_THEATRE AND
b.SES_DATE = d.PAT_DATE AND
b.SES_SESSNO = d.PAT_SESSNO AND
b.SES_THEATRE = d.PAT_THEATRE AND
c.SUR_CODE = b.SES_CONSULTANT AND
( a.SCV_DATE >= '&"Start Date"' AND
a.SCV_DATE <= '&"End Date"') AND
a.SCV_THEATRE LIKE "DU%" AND
b.SES_SPECL IN ("GYN", "OBGY" AND
d.PAT_CANCELLED = "N"
GROUP BY
c.SUR_NAME,
a.SCV_DATE
Thanks for any help you can give me
I work at a hospital and I need to aggregate data into months
I am trying to Group some data by a month and year function, the code is below
However the database wont let me, it keeps telling me I need to name my coloums, Ive tried doing this about 10 different ways with no luck eg:
ORDER BY
a.SCV_DATE or
Month or
{fn MONTHNAME(a.SCV_DATE)} AS Month
Has anyone got any ideas, I will be eternally grateful
SELECT
c.SUR_NAME,
{fn MONTHNAME(a.SCV_DATE)} AS Month,
{fn YEAR(a.SCV_DATE)} As Year,
COUNT(*),
COUNT(*)
FROM
odbc.dbo.PATIENT d,
odbc.dbo.SESSION b,
odbc.dbo.SURGEON c,
odbc.dbo.SESCORVU a
WHERE
c.SUR_TYPE = "C" AND
a.SCV_DATE = d.PAT_DATE AND
a.SCV_SESSNO = d.PAT_SESSNO AND
a.SCV_THEATRE = d.PAT_THEATRE AND
b.SES_DATE = d.PAT_DATE AND
b.SES_SESSNO = d.PAT_SESSNO AND
b.SES_THEATRE = d.PAT_THEATRE AND
c.SUR_CODE = b.SES_CONSULTANT AND
( a.SCV_DATE >= '&"Start Date"' AND
a.SCV_DATE <= '&"End Date"') AND
a.SCV_THEATRE LIKE "DU%" AND
b.SES_SPECL IN ("GYN", "OBGY" AND
d.PAT_CANCELLED = "N"
GROUP BY
c.SUR_NAME,
a.SCV_DATE
Thanks for any help you can give me