Tame Those Strings - Part 8

  • Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/sjones/tamethosestringspart8.asp

  • Hi Steve

    In this article title "QUOTES" you missed a lot, but mentioned a general stuff that can be found everywhere...

    I was expecting to see a work around when you have "'" single quote in your string, as well as tricky examples of single and double quotes.

    Then using char/varchar fields and text fields. Perhaps in Part 9, call it Advanced String Manipulation.

    I appreciate your posting.....

    Thanks....Omer.


    Omer

  • Although yes not earth shattering it did contain usefull information for those who have come across the same type of problem and presented a function that can be quite handy.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Thanks, I'm was trying to present some information on a topic that may have stumped some people. I plan on continuing with other items as I find them and I'll look at some trickier examples next time.

    Steve Jones

    steve@dkranch.net

  • Nice article.

    QUOTENAME() does handle the case of imbedded single-quote characters in strings (or any other delimiter character). Try the examples from the article with delimiter character(s) in the test strings -- nice!

    A problem I've encountered with QUOTENAME() is that it appears to work for strings up to only 128 characters, even though the return type is documented to be nvarchar(258). E.g. if I supply a 150-character literal I get back 128 characters:

    print QUOTENAME( '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890' , '''' )

    Result:

    '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678'

    Am I doing something wrong?

    Thanks...

  • Do you get this in QA or in an app? In QA, there is a 255 limit, which might be reduced to 128 for N' strings.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

  • Both QA and the app. Thanks.

    Here's something interesting... (in QA) QUOTENAME() truncates if it is passed a long regular literal and returns NULL if it is passed a long national-style literal. E.g.

    PRINT CASE

    WHEN QUOTENAME( '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890' , '''' )

    IS NULL

    THEN 'It is NULL'

    ELSE 'It is not NULL'

    END

    PRINT CASE

    WHEN QUOTENAME( N'123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890' , N'''' )

    IS NULL

    THEN 'It is NULL'

    ELSE 'It is not NULL'

    END

    Results:

    It is not NULL

    It is NULL

  • Interesting. I get the same thing.

    I'll try to dig into this.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

  • Good One. I learned new stuff. thanx a lot

    balaji


    Balaji

  • Simple stuff, and it is Great!!

     




    My Blog: http://dineshasanka.spaces.live.com/

  • Nice feature that I could use in future.

  • And note that it it still gets truncated if you increase QA's results limit to 8192 (instead of 256).

     

    John Scarborough
    MCDBA, MCSA

  • Thanks. Glad that after a year or so, this stuff still applies.

  • This is a handy little feature that for some reason I've missed before. Thanks Steve.

    -Vic

  • From BOL:

    ' character_string '

    Is a string of Unicode character data. character_string is sysname.

    and

    sysname is functionally equivalent to nvarchar(128).

    There's your limitation of 128 characters.



    Posting Data Etiquette - Jeff Moden[/url]
    Posting Performance Based Questions - Gail Shaw[/url]
    Hidden RBAR - Jeff Moden[/url]
    Cross Tabs and Pivots - Jeff Moden[/url]
    Catch-all queries - Gail Shaw[/url]


    If you don't have time to do it right, when will you have time to do it over?

Viewing 15 posts - 1 through 14 (of 14 total)

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