Link to home
Start Free TrialLog in
Avatar of newbie27
newbie27Flag for United Kingdom of Great Britain and Northern Ireland

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
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)

Open in new window

SOLUTION
Avatar of Lowfatspread
Lowfatspread
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of newbie27

ASKER

Hello Folks,

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
I was afraid that those were reserved.  Year and Month are also reserved, by the way. ;-)