Let's say you have 2 tables: a Contacts table and a PhoneNumbers table (which stores all the phone numbers for each contact). You are asked to write a query that returns each contact's name and a comma-delimited string of phone numbers for each contact, something like this:
FirstName LastName PhoneNumbers
--------- -------- --------------------------
John Smith 111-222-3333, 444-555-6666
Many developers would attempt to do this with a cursor. While a cursor could certainly be coded to do the job, there is actually a more efficient way of doing this that doesn't require cursors or temp tables.
You would write a UDF that grabs the phone numbers, and then execute the UDF within a SELECT statement, as the following code demonstrates:
Creating a PDF from a Stored Procedure in SQL Server
A short but interesting article, the author has figured out a way to create a PDF from a stored procedure without using a third party library.
2019-09-20 (first published: 2003-08-26)
73,240 reads