Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: 532 | Views in the last 30 days: 7
 
Tags
miscellaneous    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones