Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VB.net SQL Count number of x and -

Hi

I am using the following SQL query to get the result below

Select [Date],[Time],[UserID],[Name],[Gratitude], [Reframing], [Empathy], [Adaptable], [Teamwork] From Diary2 Where CompanyID = '" & Me.Label_Company.Text & "'"

How do I modify the query to get a count of the number of "x" entries for each email address
in the column UserID


User generated image
ASKER CERTIFIED SOLUTION
Avatar of rshq
rshq
Flag of Iran, Islamic Republic of 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
Another way is to add a subquery in your T-SQL that counts the email addresses, then JOIN to your Dairy2 table, then add the count to your SELECT clause
Select [Date],[Time],Dairy2.[UserID], uic.UserID_Count, [Name],[Gratitude], [Reframing], [Empathy], [Adaptable], [Teamwork] 
From Diary2 
  JOIN (SELECT UserID, COUNT([UserID]) as UserID_Count FROM Diary2 Where CompanyID = '" & Me.Label_Company.Text & "' GROUP BY UserID) uic ON Dairy2.UserID = uic.UserID
Where CompanyID = '" & Me.Label_Company.Text & "'

Open in new window


<edit>
Disregard, didn't read the question correctly.
Avatar of Murray Brown

ASKER

thanks very much