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)

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: 1575 | Views in the last 30 days: 3
 
Related Articles
FORUM

declaring datatypes

sqlserver_datatype

FORUM

DataType Issue in SQL 2005!

Timestamp DataType ??

FORUM

datatype to store only date in SSIS

date datatype

FORUM

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

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

Tags
coalesce    
concat()    
isnull    
string manipulation    
 
Contribute