sql query to format numbers

  • Hi all,

    Need assistance in building sql server query to format numbers as dont want to handle this formatting in front end.

    required format as under:

    format-number(@ScheduledCapacity,'###,##0')

    appreciate your help.

  • This kind of formatting should be done in the front end. SQL doesn't have a lot of string formating functions (which front end apps tend to do) and presentation should be done in the presentation layer.

    To do what you want will need probably a couple of CAST, maybe round (or ceiling or floor) and, by the looks of things, some string concatenation as well.

    What should the following display as?

    12

    0.2658441

    5215456.12345

    2.3

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • I have limitation not to handle it in front end.

    It should be like:

    123,456,78

  • I gave 4 pieces of sample data. How should those 4 be formatted?

    Why the limitation? the front end is the correct place to do this, doing it in SQL is going to be a pain.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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