Add dollar to the result of floor value

  • Hi,

    I am using this query to get the nearest value and rounding it.

    floor(Price*DollarPrice) as Dollars

    This returns result like below

    31

    34

    567

    Now I just need to add dollar symbol before the result. Please suggest me.

  • Formatting of display values is best done inside the application. Application programming languages are far better in manipulating strings.

    If you realy want to do it in SQL you need to convert the value to a string and then add the $symbol to it, like:

    SELECT '$' + CAST(floor(Price*DollarPrice) AS VARCHAR(10)) as Dollars

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • '$' + cast(floor(Price*DollarPrice) as varchar)

    This will give you $xx. You won't be able to do any calculations on that though. If you need to do anything to the numbers it will probably be best formatting the final output as a money\currency datatype in the front end.


    On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" ... I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
    —Charles Babbage, Passages from the Life of a Philosopher

    How to post a question to get the most help http://www.sqlservercentral.com/articles/Best+Practices/61537

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

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