STR

  • Comments posted to this topic are about the item STR

    Regards,
    Ravi.

  • Thanks, always nice to be reminded of the basics ...

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • A new one for me ...

    thanks

    ~ demonfox
    ___________________________________________________________________
    Wondering what I would do next , when I am done with this one :ermm:

  • thanks for the question.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • new things for me...

    thanks

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • Easy point! thanks..

  • Nice question. Thanks!


    Sujeet Singh

  • I knew about the STR function, but was not entirely sure what the optional arguments meant, so I decided to check Books Online before answering.

    I must say that I was a bit surprised to see an example that is EXACTLY identical to today's question...

    Coincidence?


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Hugo Kornelis (10/18/2012)


    I must say that I was a bit surprised to see an example that is EXACTLY identical to today's question...

    Coincidence?

    You cynic Hugo. 😛

    But if the question serves to educate, test or whatever - I don't see the harm

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • I initially thought '23.45' as I would have thought the length requirement of 2 would 'count' from the smallest to the largest unit, but decided to test the statement before answering. I was surprised to get **, was not aware of this element of STR. An undeserved point for me, I think. Thanks for the question.

    ---

    Note to developers:
    CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
    So why complicate your code AND MAKE MY JOB HARDER??!:crazy:

    Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
    My blog: http://uksqldba.blogspot.com
    Visit http://www.DerekColley.co.uk to find out more about me.

  • Good question

    But the explanation is very poor, inaccurate. For example the length of the expression "123.45" is 6, but str(123.45,4,2) is not '**' as suggested by the explanation but '123'.

    Tom

  • Good thing that it is "**"

    Wrong information is no information.

  • Hugo Kornelis (10/18/2012)


    I knew about the STR function, but was not entirely sure what the optional arguments meant, so I decided to check Books Online before answering.

    I must say that I was a bit surprised to see an example that is EXACTLY identical to today's question...

    Coincidence?

    I don't think it is coincidence :hehe: but no problem as the question servers the purpose.

    Other benefit is that the author of the question has an "exact" explaination available on msdn 😀


    Sujeet Singh

  • L' Eomot Inversé (10/18/2012)


    Good question

    But the explanation is very poor, inaccurate. For example the length of the expression "123.45" is 6, but str(123.45,4,2) is not '**' as suggested by the explanation but '123'.

    It is an exact copy from the http://msdn.microsoft.com/en-us/library/ms189527(v=sql.100).aspx, first example!

  • @Cassie (10/18/2012)


    L' Eomot Inversé (10/18/2012)


    Good question

    But the explanation is very poor, inaccurate. For example the length of the expression "123.45" is 6, but str(123.45,4,2) is not '**' as suggested by the explanation but '123'.

    It is an exact copy from the http://msdn.microsoft.com/en-us/library/ms189527(v=sql.100).aspx, first example!

    The examples on that page contain no explanations, so how can the explanation be an exact copy of something in one of them? Also, the length and decimal parameters are not the ones in the first example, but the ones in the second.

    I guess the real point is that the length of '123.45' is irrelevant to whether '**' turns up, all that is relevant is the length of '123', since str is perfectly happy, if neccessary to get a result other than '**', to thow away everything after the decimal point and ignore the decimal argument of str. This is made absolutely clear by the text onm the page you refer to.

    Incidentally, your link points to 'Microsoft Website': you have the display text and the URL the wrong way round. That makes it not a useful clickable link; doesn't matter as the display text tells us where to go.

    Tom

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

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