I am fairly new to sql. I am trying to get a count of activities done by specified people in a persons table.
Pseudo sql query:
select count
from activities table a
left outer join persons table p
where p.lastName + ', ' + p.firstName like 'LastName1, FirstName1 | LastName2, FirstName2 |..."
What is a good way to compare the names in the persons table to a pipe delimited list of names passed as a parameter in an SSRS report?
Probably you are looking for something like this:
Total of activities for persons of interest
SELECT COUNT(*) activities_count
FROM activites a LEFT JOIN
persons p ON a.person_id = p.id
WHERE 'Lee, Mark | Doe, Jhon' LIKE '%' + p.lastName + ', ' + p.firstName + '%'
Number of activities per person
SELECT p.id, COUNT(*) activities_count
FROM activites a LEFT JOIN
persons p ON a.person_id = p.id
WHERE 'Lee, Mark | Doe, Jhon' LIKE '%' + p.lastName + ', ' + p.firstName + '%'
GROUP BY p.id
Here is SQLFiddle
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.