Reputation: 75
I'm working on table that will create output with quarter by quarter increases in figures. I basically have two columns with values for each quarter ("Q1 2013"
and "Q4 2012"
). I have created another column that gives the difference between the two values ("Q/Q"
). I want to create another column that will then convert the difference as a percentage ("Q%"
). My code currently looks like this:
SELECT STATION, "Q4 2012", "Q1 2013", "Q/Q", (("Q/Q"/"Q4 2012") * 100.00) AS "Q%"
FROM "STATION FIGURES";
The output I get in Q%
is only 0.00
which is kind of annoying. Does anyone know what I'm doing wrong? Would appreciate any help.
Upvotes: 3
Views: 10822
Reputation: 1269533
SQL Server does integer division when the two values are integers. Convert one to a decimal representation or float:
SELECT STATION, "Q4 2012", "Q1 2013", "Q/Q",
((cast("Q/Q" as float)/"Q4 2012") * 100.00) AS "Q%"
FROM "STATION FIGURES";
Upvotes: 2