Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help Converting INT to DECIMAL

Author  Topic 

dcw0405
Starting Member

1 Post

Posted - 2012-09-06 : 17:44:10
Hello!

I have the following (LONG) expression in my SELECT statement, I need help because it runs, but it's giving me a whole number, not the decimal format I need. Because it's so long and tedious, I'm having a hard time knowing what to put where and if it's even possible. The result is giving me an INT and I want it to four decimal places. If anyone has any tips, I'd be SO grateful! Thank you!

CREATE TABLE #bdaymoney (name_n CHAR(12), svc_d CHAR(11), eff_d CHAR(11), time INT)

INSERT #spe_downgrade
SELECT sq.name_n, convert(char(10), sq.svc_d, 101), convert(char(10), ud.eff_d, 101),
CASE WHEN day(ud.eff_d) < day (sq.svc_d)
THEN (((year(ud.eff_d) - year(sq.svc_d)) + (month(ud.eff_d)-month(sq.svc_d)) / 12)-0.0833)
ELSE ((year(ud.eff_d) - year(sq.svc_d)) + (month(ud.eff_d)-month(sq.svc_d)) / 12) END AS time


So running this, if eff_d = 06/27/2010 and svc_d = 12/07/1999, I want it to produce 10.5000, but right now it just produces 11. I know this is confusing but any help would be appreciated for this n00b. Thank you!!

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-09-06 : 19:00:24
If you do integer math you get integer results. Try changing the 12 to 12.00 or someting that is not an integer. FOr example:
SELECT 100/12, 100/12.0
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-09-13 : 04:31:37
More infor on http://beyondrelational.com/modules/2/blogs/70/posts/10825/beware-of-implicit-conversions.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -