1

I have a query from Access where I caluclated the percentage score of three seperate numbers Ex:

AFPercentageMajor: [AFNumberOfMajors]/([AFTotalMajor]-[AFMajorNA])

which could have values of 20/(23-2) = 95%

I have imported this table into my SQL database and tried to write a expression in the view (changed the names of the columns a bit)

AF_Major / (AF_Major_Totals - AF_Major_NA)

I tried adding *100 to the end of the statement but it only works if the calculation is at 100%. If it is anything less than that it puts it as a 0.

I have a feeling it just doesn't like the combincation of the three seperate column names. But like I said I'm still learning so I could be going at this completely wrong!

4

1 に答える 1

3

SQL Server は整数除算を行います。値の 1 つを浮動小数点表現に変更する必要があります。以下が機能します。

cast([AFNumberOfMajors] as float)/([AFTotalMajor]-[AFMajorNA]) 

これに 100 を掛けると、パーセンテージ値を取得できます。

于 2013-08-14T22:10:51.667 に答える