Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««12345

Concatenation Cursor Expand / Collapse
Author
Message
Posted Wednesday, March 31, 2010 2:47 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, July 14, 2014 10:08 AM
Points: 754, Visits: 3,816
I must be missing something really simple here, but what happened to the last comma?
I would think that the result would have to end in a comma since what is stringed together ends in a comma -> @MaleNames + ', '

Never mind - I see that it actiually adds the [name] after the ISNULL funtion.


______________________________________________________________________
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
Post #894215
Posted Wednesday, March 31, 2010 2:58 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 5:28 PM
Points: 5,969, Visits: 8,224
The query uses IsNull(@MaleNames + ', ','') + [name].

When @MaleNames is NULL, @MaleNames + ', ' is NULL as well, so the ISNULL kicks in and replaces the NULL with an empty string, to which [name] is concatenated. This leaves us with a single name and no comma.

When @MaleNames is not NULL (but, for instance, a single name and no comma), @MaleNames + ', ' adds a comma to that name, the ISNULL does nothing, and then [Name] is concatenated - so now we have two names, seperated by a comma.

After that it continues to add ', ' and a name to the string, until processing stops.

DISCLAIMER: This description is based on the assumption that SQL Server will process the rows one by one and not reset the variable in between; this is often observed but undocumented behaviour and should not be relied on. Other behaviour can happen anytime (and has in fact sometimes been observed).



Hugo Kornelis, SQL Server MVP
Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Post #894231
Posted Wednesday, March 31, 2010 3:17 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Monday, July 14, 2014 10:08 AM
Points: 754, Visits: 3,816
Thanks Hugo, I should have mulled over that question just a few more minutes before asking it.

______________________________________________________________________
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
Post #894239
Posted Thursday, April 1, 2010 3:18 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:31 AM
Points: 11,194, Visits: 11,137
Hugo Kornelis (2/26/2010)
I'll raise the red flag (if I only knew how to get red text here):

THIS METHOD IS NOT DOCUMENTED, NOT SUPPORTED, AND NOT GUARANTEED TO RETURN WHAT YOU EXPECT

Like that




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #894529
« Prev Topic | Next Topic »

Add to briefcase «««12345

Permissions Expand / Collapse