|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, June 26, 2009 7:10 AM
Points: 4,
Visits: 6
|
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 12:43 AM
Points: 582,
Visits: 1,601
|
|
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.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Saturday, May 18, 2013 1:47 PM
Points: 51,
Visits: 773
|
|
I find the use of XMl to be a cleaner method to concatenate rows into a single value:
select Fname+',' From Employee For XML Path(''), Type
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, April 05, 2012 2:35 PM
Points: 2,007,
Visits: 767
|
|
| 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.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, June 26, 2009 7:10 AM
Points: 4,
Visits: 6
|
|
| 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.
|
|
|
|
|
Valued Member
      
Group: General Forum Members
Last Login: Saturday, May 18, 2013 1:47 PM
Points: 51,
Visits: 773
|
|
| Agreed, but XML constructs are part of T-SQL and therefore, always available
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Today @ 3:23 PM
Points: 494,
Visits: 3,010
|
|
Edward Boyle (6/26/2009) Agreed, but XML constructs are part of T-SQL and therefore, always available
If you are using SQL Server 2005 and above... FOR XML PATH is not available in SQL Server 2000.
|
|
|
|