Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying datatype INT as Decimal

Status
Not open for further replies.

nread

Technical User
Oct 31, 2001
58
GB
Is it possible to show a Int value as a decimal..? I am trying to work out a variance based on a total difference/total*100, my datatypes are integers and the result returned is 0.

Is this possible...?

Here is my query and results...

Thanks for any ideas.

SELECT
TMI.[Date],
AllNat.varcharNatco AS NATCO,
AllNat.TotalDownloads AS [Natco Downloads],
TMI.TotalDownloads AS [TMI Downloads],
(AllNat.TotalDownloads - TMI.TotalDownloads) AS [Difference],
(((AllNat.TotalDownloads - TMI.TotalDownloads) /TMI.TotalDownloads)*100) As [% Varience]
FROM
@TMI as TMI, tblAll_Natcos_Summary as AllNat
WHERE TMI.varcharNatco = AllNat.varcharNatco
AND TMI.[Date] = AllNat.[Date]


--RESULTS

2004-01-22 00:00:00.000 at 4911 4890 21 0
2004-01-21 00:00:00.000 nl 2560 2505 55 0
2004-01-22 00:00:00.000 nl 2455 2475 -20 0
2004-01-21 00:00:00.000 uk 11829 11804 25 0
2004-01-22 00:00:00.000 uk 11648 11635 13 0
 
1.0 * difference/total*100

Or convert one of the values to the precision you require.


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
I managed to get the result i wanted using :

(CONVERT(MONEY, (AllNat.TotalDownloads - TMI.TotalDownloads)/(CAST(TMI.TotalDownloads AS FLOAT)))*100)

Thanks all the same

nick
 
You probably don't need the float cast - and it might cause problems.
try
(CONVERT(MONEY, (AllNat.TotalDownloads - TMI.TotalDownloads))/TMI.TotalDownloads)*100

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Ok i will give it a go ..

Ta
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top