brazumich (5/18/2011) I'm sure there is code from 1904 in there that does all this :)

LOL... 1974 might be closer to the time. Or even 1989 when C89 came out...It is very old behavior. Those of you that recognize these dates might be able to guess I have been researching if this behavior of STUFF started in straight C, ANSI C, or C++.

You are right about STUFF inserting of a single space string for NULL, that is a SYBASE thing only. It comes from some other old behavior.

"This is not true for all database implementations. In an Oracle RDBMS for example NULL and the empty string are considered the same thing and therefore 'Fish ' || NULL || 'Chips' results in 'Fish Chips'." (concatenation)

That link doesn't say what STUFF does with a NULL last argument. So how can you say it tells us it worked that way for however many years, when it's the result of a NULL last argument that's at issue in this converstaion?

That's what got me, too.I thought concatenating NULL would yield NULL,but it seems like it applies Coalesce(..., '') or IsNull(..., '') to the last argument before concatenating it. This behavior is not consistent with that of

We might consider adding the ANSI SQL OVERLAY function in the future based on more customer feedback...

OK, the wording through me off...I thought Umachandar was alluding to a new server option that could be SET, but in fact OVERLAY is a scalar function defined by in the ANSI SQL Standard that does not yet exist in SQL Server. OVERLAY would do the same work as STUFF but could be implemented to properly handle NULL inputs. This was the only article I could find that defined it:

OVERLAYThe OVERYLAY function embeds one string into another and returns the result.

SQL2003 Syntax

OVERLAY(string PLACING embedded_string FROM start[FOR length])

If any of the inputs are NULL, the OVERLAY function returns a NULL. The embedded_string replaces the length characters in string starting at character position start. If the length is not specified, then the embedded_string will replace all characters after start in string.

DB2, MySQL, Oracle, and SQL Server

These platforms do not have support for the OVERLAY function. You can simulate the OVERLAY function on these platforms by using a combination of SUBSTRING and the concatenation operator.

That link doesn't say what STUFF does with a NULL last argument. So how can you say it tells us it worked that way for however many years, when it's the result of a NULL last argument that's at issue in this converstaion?

Been waiting to answer just that question. I will give you the same answer I was given... You should always test any code. Test it a hundred times if you dont know exactly how something works or have not used it before.I know it sounds harsh, but this is how STUFF is. STUFF has always been this way and STUFF will continue to be this way. STUFF is everywhere, but STUFF does not act the same everywhere. That is just how STUFF and the world works. If you do not understand STUFF, or the documentation for STUFF, you should test your STUFF. Afterwards take a look again at the documentation and STUFF. If you realy learned some STUFF, you should understand STUFF and the differances of other STUFF better. Hopefully you can find the Humor in how STUFF is. Most people that can't laugh at STUFF have a harder life than others.

That link doesn't say what STUFF does with a NULL last argument. So how can you say it tells us it worked that way for however many years, when it's the result of a NULL last argument that's at issue in this converstaion?

Been waiting to answer just that question. I will give you the same answer I was given... You should always test any code. Test it a hundred times if you dont know exactly how something works or have not used it before.I know it sounds harsh, but this is how STUFF is. STUFF has always been this way and STUFF will continue to be this way. STUFF is everywhere, but STUFF does not act the same everywhere. That is just how STUFF and the world works. If you do not understand STUFF, or the documentation for STUFF, you should test your STUFF. Afterwards take a look again at the documentation and STUFF. If you realy learned some STUFF, you should understand STUFF and the differances of other STUFF better. Hopefully you can find the Humor in how STUFF is. Most people that can't laugh at STUFF have a harder life than others.

Unfortunately that tells us that things should be checked by testing. It doesn't tell us why you claimed that the page you referenced said something it quite clearly didn't say. I suggest you read the page again to test whether it actually says what you claimed it said - apply your own "check everything by testing" to your own assertion (which certainly needs testing, as it was completely wrong).

I think (before there is some serious bloodletting here), that perhaps what M$ needs to do is update the documentation so that it matches the functionality that was inherited/borrowed/etc from Sybase. We already know they ain't gonna change how it works, so doc is the next best thing.

Perhaps Microsoft could just copy/plagarize the explanation pointed to by an earlier poster; I think it's on the third or 4th page of comments.

Oh, and to SanDroid, I personally would like to have the right STUFF; I could be an astronaut then