nest cast & convert select statements

  • Hi. Would anyone have an example of how to nest a cast select statement & convert select statement? Thanks.

  • Do you have an example of what you're trying to achieve?

    _____________________________________________________________________
    - Nate

    @nate_hughes
  • RP_DBA (9/12/2008)


    Do you have an example of what you're trying to achieve?

    Hi. Trying to convert from float to decimal value and then report the number of characters.

    i.e. float = -888.99 and require a returned result of 7 in this case

  • Original answer to you was faulty so I removed same. Sorry about that.

    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]

  • This will also work for the example given, however, the number of characters returned is directly dependent on the precision and scale you specify.

    declare @num float

    set @num = -888.99

    select len(convert(decimal(10,2),@num))

    Converting to varchar does some strange things

    declare @num float

    set @num = -888.9999

    select len(convert(varchar,@num)) -- returns 4

    set @num = -888888.99

    select len(convert(varchar,@num)) -- returns 7

    set @num = -8888888.99

    select len(convert(varchar,@num)) -- returns 10

    Sorry, don't know if we're being much help here...

    _____________________________________________________________________
    - Nate

    @nate_hughes
  • Thank you bitbucket & Grasshopper. I will try your suggestions.

Viewing 6 posts - 1 through 5 (of 5 total)

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