I'm trying to work out the most efficient way to count the number of occurrences that a keyword appears in my document table based on a specific list of document ids passed into my stored procedure.
The SP takes a parameter @DocIds
as a comma seperated list e.g. 100, 2010, 2340
What I am wanting to do is select the records where the DocID exists in the comma seperated list I'm passing in and records the keywords into a temporary table but also keep a count if the keyword has already been added to my temp table.
So for example (document table):
DocID | Keywords
-----------------------------
100 | Test, Document, Info
2010 | Document, users
4 | ....
2340 | users, client
Temp table would return:
Keyword | Count
Test | 1
Document | 2
Info | 1
users | 2
client | 1
I'm sure some SQL guru has a great solution for this any help would be greatly appreciated.
Many thanks M