A column (called "nettime") I'm pulling from a table (payr_paydetail) is of the float data type (size is 8). I need to use the SUM function on that column AND (here's the problem part that I can't figure out) I need to have up to two zeros after the decimal, regardless of whether the result is a whole number, or one digit after the decimal. I.e. if the SUM of the column is an even 108, then the result should be 108.00, not 108, or 108.0, or 108.0000.
The basic query looks like this:
SUM(pd.nettime) as HoursWorked
FROM dbo.payr_PayDetail pd
WHERE (pd.statusid = 12)
Now, I've spent a lot of time on this and I've tried a number of things, all to no avail. Here's a list of what I've tried:
CAST(ROUND(SUM(pd.nettime),2) as float) AS HoursWorked
CAST(SUM(ROUND(pd.nettime,2)) as varchar) AS HoursWorked
CAST(SUM(pd.nettime) AS dec(4,2)) AS HoursWorked
CONVERT(dec(4,2), (SUM(pd.nettime))) AS HoursWorked
CAST(CONVERT(dec(4,2), (SUM(pd.nettime))) AS varchar) AS HoursWorked
The last three lines above all generate the error, "Arithmetic overflow error converting float to data type numeric." It's my understanding (and I'm reeeeeeaaaaaaal new to to SQL, so correct me if I'm wrong!) that the reason for the error is that in those three instances I'm trying to convert a float data type with a higher precision to the decimal data type which is of a lower precision.
I (and my boss who wanted this done yesterday!) would greatly appreciate it if someone could help me out here.
Thanks in advance!
f u cn rd ths, u cn gt a gd jb n prgrmng