﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Richard Spalding  / Using Coalesce in a stored Procedure / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 18 Jun 2013 20:29:11 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Using Coalesce in a stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic734363-1565-1.aspx</link><description>[quote][b]Edward Boyle (6/26/2009)[/b][hr]Agreed, but XML constructs are part of T-SQL and therefore, always available[/quote]If you are using SQL Server 2005 and above... FOR XML PATH is not available in SQL Server 2000.</description><pubDate>Fri, 26 Jun 2009 13:35:04 GMT</pubDate><dc:creator>j.a.c</dc:creator></item><item><title>RE: Using Coalesce in a stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic734363-1565-1.aspx</link><description>Agreed, but XML constructs are part of T-SQL and therefore, always available</description><pubDate>Fri, 26 Jun 2009 07:52:43 GMT</pubDate><dc:creator>Edward Boyle-478467</dc:creator></item><item><title>RE: Using Coalesce in a stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic734363-1565-1.aspx</link><description>All great comments!! I agree that XMI might give you cleaner results. this example was written to show how to concatinate rows when XMI isnt an option in stored procedures or SQL only is required.</description><pubDate>Fri, 26 Jun 2009 07:13:51 GMT</pubDate><dc:creator>rspalding</dc:creator></item><item><title>RE: Using Coalesce in a stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic734363-1565-1.aspx</link><description>I'm with David, the use of two rightmost strings in the COALESCE function doesn't make sense. You'll never get to the last (third) parameter. With COALESCE only the last (rightmost) parameter should ever be a fixed value and each of those to the left of it should be variables or columns that could be null.</description><pubDate>Fri, 26 Jun 2009 06:59:21 GMT</pubDate><dc:creator>Noel McKinney</dc:creator></item><item><title>RE: Using Coalesce in a stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic734363-1565-1.aspx</link><description>I find the use of XMl to be a cleaner method to concatenate rows into a single value:select Fname+','From EmployeeFor XML Path(''), Type</description><pubDate>Fri, 26 Jun 2009 06:00:37 GMT</pubDate><dc:creator>Edward Boyle-478467</dc:creator></item><item><title>RE: Using Coalesce in a stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic734363-1565-1.aspx</link><description>Please correct me if I've misunderstood but....Coalesce returns the first non-null value among its parameters (from first to last).  Given that your second parameter is not null (a space), the third parameter is superfluous.  COALESCE(@COUNTYCRITERIA,' ',',')If you initialise your variable @COUNTYCRITERIA to an empty string first, then you don't have to coalesce anything.i.e.DECLARE @COUNTYCRITERIA varchar(1000)SET @COUNTYCRITERIA=''SELECT....Regards,David McKinney.</description><pubDate>Fri, 26 Jun 2009 00:32:44 GMT</pubDate><dc:creator>David McKinney</dc:creator></item><item><title>Using Coalesce in a stored Procedure</title><link>http://www.sqlservercentral.com/Forums/Topic734363-1565-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/Stored+Procedure/67194/"&gt;Using Coalesce in a stored Procedure&lt;/A&gt;[/B]</description><pubDate>Sat, 13 Jun 2009 10:20:04 GMT</pubDate><dc:creator>rspalding</dc:creator></item></channel></rss>