Home > database >  SQL - converting the result of a sum of COUNTs
SQL - converting the result of a sum of COUNTs

Time:10-12

Apologies if I don't format correctly as I'm quite new to SE.

I currently have a T-SQL statement that calculates the sum of two COUNTS. This is the basic structure:

select 
    ((select convert(decimal(10,2), count(*)) 
      from sometable 
      where conditions)
     /
     (select convert(decimal(10, 2), count(*)) 
      from someothertable 
      where conditions)) as Foobar

That returns a result of a decimal, but to 12 decimal places. I need to convert the result to a decimal with two DP, then the result of that to a string - but I'm not sure how to go about this as I'm not sure how to manipulate the result that's returned.

TIA Si

CodePudding user response:

select convert(decimal(10,2),(

(select count(*) from sometable where conditions)

/

(select count(*) from someothertable where conditions)

)) as Foobar
  • Related