newbie27
asked on
sql syntax
Hello Experts
I am trying to run the attached SQL to fetch the data by the user type. All I am trying is to count the number of
registrations by month and show it in the following order
INTERNAL EXTERNAL Year Month
18 2 2011 9
4 1 2011 10
however the query i am using giving me the following result
NumCodes UserTpe Year Month
2 EXTERNAL 2011 9
1 EXTERNAL 2011 10
18 INTERNAL 2011 9
4 INTERNAL 2011 10
Can someone please advise?
Thanks
S
I am trying to run the attached SQL to fetch the data by the user type. All I am trying is to count the number of
registrations by month and show it in the following order
INTERNAL EXTERNAL Year Month
18 2 2011 9
4 1 2011 10
however the query i am using giving me the following result
NumCodes UserTpe Year Month
2 EXTERNAL 2011 9
1 EXTERNAL 2011 10
18 INTERNAL 2011 9
4 INTERNAL 2011 10
Can someone please advise?
Thanks
S
SELECT COUNT(dbo.MatchCertificate.MatchCodeID) AS NumCodes, dbo.MatchCertificateHistory.UserType,
Year(MatchHistDateAdded) AS YEAR, Month(MatchHistDateAdded) AS MONTH
FROM dbo.MatchCertificate INNER JOIN
dbo.MatchCertificateHistory ON dbo.MatchCertificate.MatchCodeID = dbo.MatchCertificateHistory.MatchCodeID
WHERE (dbo.MatchCertificateHistory.StatusID = 'REGISTERED') AND
(dbo.MatchCertificateHistory.MatchHistDateAdded > '2010-11-01')
GROUP BY dbo.MatchCertificateHistory.UserType, Year(GiftHistDateAdded), Month(MatchHistDateAdded)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I was afraid that those were reserved. Year and Month are also reserved, by the way. ;-)
ASKER
Thank you very much for your input.
8080_Diver's solution has worked for me. I believe INTERNAL and EXTERNAL are reserve words in SQL? I have to change it slightly and it works.
Thanks