in reply to Perl solution for SQL problem?

I'm trying to make sense of your question, but I fail. First, Person_count is of type INT, the table Cases doesn't have a column of type INT, so it's totally unclear how Person_count is a cross reference to that table.

Having said that, your question seems about a fragment of an SQL statement, and that fragment doesn't mention Person_count, so, why this information about said column is relevant remains unclear.

And then the question Do I require a bit of Perl script to do this or can I do it with just T-SQL. Considering you give the query as an SQL fragment, what makes you think you can't do it in SQL? It's like pointing to a red bird and asking whether a bird can be red....

Abigail