SQL Clone
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)

Create string from table

By Swashbuckler,

I needed something that would return a list of email addresses from a particular column in a table, based on a condition in a joined table.

The above script will work with both the COALESCE or the ISNULL function. For both the datatype may need to be adapted (as shown here). The result of ISNULL() always takes on the datatype of the first parameter (regardless of whether it is NULL or NOT NULL). COALESCE works more like a CASE expression, which returns a single datatype depending on precendence and accommodating all possible outcomes.

The difference between the first and second example is purely to illustrate the difference in the formatting of the string.

Total article views: 1580 | Views in the last 30 days: 2
Related Articles

declaring datatypes



DataType Issue in SQL 2005!

Timestamp DataType ??


datatype to store only date in SSIS

date datatype


"/" allowed in VARCHAR Datatype?????

"/" allowed in VARCHAR Datatype?????

string manipulation