A Funny Substring NULL

  • Comments posted to this topic are about the item A Funny Substring NULL

  • "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

     

  • johan.vandamme wrote:

    "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/

  • 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


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply