SQLUSA

Microsoft SQL Server 2000 Best Practices

 

How to create a list of publishers with COALESCE?

 

The following samples with book publishers demonstrates the usage of COALESCE:

 

USE pubs
go

DECLARE @Publishers VARCHAR(4096)
SELECT @Publishers = COALESCE(@Publishers + ', ', '') + pub_name
FROM publishers

SELECT Publishers = @Publishers
GO

It will print: McGraw-Hill, New Moon Books, Binnet & Hardley, Algodata Infosystems, Five Lakes Publishing, amazon.com, Ramona Publishers, GGG&G, Scootney Books, Lucerne Publishing, Double Day, Harper & Collins.


The World Leader in SQL Server Training
 
SQLUSA.com Home Page