November 29, 2021 at 12:00 am
Comments posted to this topic are about the item A Funny Substring NULL
November 29, 2021 at 1:57 pm
"All is naught for not"
Or you can directly convert a NULL value to a string literal directly from the table with the ISNULL() function:
SELECT SUBSTRING(ISNULL(txt,'NULL'),1,2), txt from MyTable
November 29, 2021 at 3:25 pm
"All is naught for not"
Or you can directly convert a NULL value to a string literal directly from the table with the ISNULL() function:
SELECT SUBSTRING(ISNULL(txt,'NULL'),1,2), txt from MyTable
Why would you do this? A string 'NULL' is not the same as a NULL. This code will return 'NU', which is definitely not valid data.
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
November 29, 2021 at 9:31 pm
I have to admit that I've never done a SUBSTRING on a NULL directly as in the question. I've not seen anyone even try to do such a thing in the last 24 years and I can't think of a single use case for it except as part of a knowledge test. It DOES make a great knowledge question and also demonstrates that the NULL will NOT be implicitly converted in this case.
That makes it one hellava an "SQL OOLIE"! Nice question! Here's your honorary "Dolphins for a day"!
With origins from the world of “Submarine ‘Dolphin’ Qualification” questions, an “Oolie” is a difficult question to answer, or the knowledge or fact needed to answer such a question, that may or may not pertain to one's duties but tests one's knowledge of a system or process to the limit.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply