Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favourite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved 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: 1534 | 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 (t-sql)    
isnull    
string manipulation    
 
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