How to use the count (*) and the substitution operation in SQL statements

I load big data into a database,

I want to know how this happens.

I use

select count(*) from table

to check how many lines are loaded. and now I want to get a percentage of the process. I tried:

select ( count(*)/20000 ) from table

and

select cast(  ( count(*)/20000 )  as DECIMAL(6,4)  ) from table

but they all return 0,

so how can i do this?

And it is better if he can show a percentage.

thanks

+4
source share
2 answers

Integer division returns an integer, the decimal part is truncated. You can divide into 20000.0:

select ( count(*)/20000.0 ) from table

MSDN / (Share)

If the integer dividend is divided by an integer divisor, the result is an integer that has some fractional part of the result.

+3
source
Select CONVERT(DECIMAL(6,4),COUNT(*)) / CONVERT(DECIMAL(6,4),20000) FROM TABLE

- , , , . DECIMAL (6,4) , DECIMAL (6,3).

+1

All Articles