Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Returning a Comma Delimited string

By David Todd,

One of the small quirks of SQL is that it can add each row to a variable.

In the most common case, this is used to generate a comma delimited list.

The script shows how to do this wiht a scalar function, so that multiple rows are returned.

The script shows calculating the column sum the hard way and compares the result to the standard aggregate function SUM().

Of interest is that apart from the output, both sum and incrementing the variable had the same execution plan cost.

Total article views: 549 | Views in the last 30 days: 2
 
Tags
miscellaneous    
 
Contribute