itjanko
itjanko

Reputation: 11

How can I Roundoff in SQL with a sum function

In My SQL Code I am trying to round the value to 2 decimal point with sum

select ((SUM(Round((CAST(PE.GstTotal as float) * PE.Quantity) / 2 ),2))) FROM [dbo].[PharmacyEntry] PE

But I am getting an error. Could someone correct me on this. Error

Upvotes: 0

Views: 211

Answers (2)

Zakaria
Zakaria

Reputation: 4796

You're providing 2 as a second parameter to sum instead of round. Try this:

select SUM(Round((CAST(PE.GstTotal as float) * PE.Quantity) / 2 , 2)) 
FROM [dbo].[PharmacyEntry] PE

Upvotes: 1

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89361

It's sometimes helpful to vertically align all your parenthesis pairs to see where you've got one wrong:

    select 
    (
      (
        SUM
        (
          Round
          (
            (
              CAST
                (
                   PE.GstTotal as float
                ) 
                * 
                PE.Quantity
            ) 
            /
            2 
          ),
          2
        )
      )
    ) 

FROM [dbo].[PharmacyEntry] PE

Upvotes: 1

Related Questions