Cold fire
Cold fire

Reputation: 21

Aliquot results after division

I'm trying to get results with no aliquot + addig the percent mark to them.

I'm using below row code:

(cast(step_out_quantity as float) / step_in_quantity *100.00) as Yield

My output column looks like this:

Yield
57.1428571428571
100
100
100
87.5
100
90.9090909090909
98.1132075471698
99.1525423728814
93.3333333333333

What is my best option to achieve the next results:

Yield
57%
100%
100%
100%
87%
100%

Upvotes: 0

Views: 53

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269543

In standard SQL you can do:

select concat(cast(cast(step_out_quantity*100 as int
                       ) / step_in_quantity as varchar(255)
                  ), '%'
             ) as Yield

In SQL Server, you can do:

select cast(floor(step_out_quantity * 100) as varchar(255)) + '%'

Upvotes: 1

Related Questions