Link to home
Start Free TrialLog in
Avatar of thomasm1948
thomasm1948Flag for United States of America

asked on

SQL Stored procedure to count each row that has the same value

I have a question in concerns with counting rows.  I have two tables

table1
CaseID, UserID, CaseTitle, CaseDescription

Table2
ID, CaseID, CaseNotes

How can I create a stored procedure that will enable me to count al of the notes for the same CaseID and only select table1 and add an extra column for the number of case notes for each case ID

thank you for all of your help

Avatar of chapmandew
chapmandew
Flag of United States of America image

select caseid, casenotes, count(*)
from tablename
group by caseid, casenotes
having count(*) > 1
Avatar of thomasm1948

ASKER

How would that work if I have multiple caseids and I am trying to add an extra column to indicate the notes count

In table1 the casid is the primary key and table2 casid is the foriegn key.  I would like to just view table one with the additional column to view the notes count

thank you for all of your help
ASKER CERTIFIED SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America 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
It worked perfectly

Thank you for all of your help as it is greatly appreciated