Add inf a currency symbol to a calculated column

  • The question is in the title. The code is

    SELECT SalesLT.Product.Name

    ,SalesLT.Product.Color

    ,SalesLT.Product.StandardCost

    ,SalesLT.Product.ListPrice

    ,SalesLT.Product.ListPrice - SalesLT.Product.StandardCost AS Profit

    ,SalesLT.ProductModel.Name AS SubCatNameType

    ,SalesLT.Product.ListPrice

    ,SalesLT.Product.Name AS SubCatName

    FROM SalesLT.Product INNER JOIN

    SalesLT.ProductModel ON SalesLT.ProductModel.ProductModelID = SalesLT.ProductModel.ProductModelID

     

    Many thanks

  • Here are two ways.  My preference is for the second one.  Since the FORMAT function was introduced in SQL Server 2012 (afaik) it's been known to have performance issues.  Maybe it changed with the introduction of inline scalar functions in 2019.  Idk tho and I'm not aware any recent retests.  Afaik most of the time the formatting of output data is handled by some user application and not the database query

    select format(cast(12.75 as decimal(14,2)), 'C', 'en-US') format_dollar,
    concat('$', cast(12.75 as decimal(14,2))) cast_dollar;

     

    Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können

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

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