Oct 24, 2003 #1 Digga Programmer May 11, 2001 84 GB Hi Can someone tell me how to round a decimal datatype value up to the nearest .5 in MS SQL. For example: 1.2 = 1.5 1.4 = 1.5 1.6 = 2.0 1.8 = 2.0 etc., etc. Many thanks in advance. Digga Sharing Knowledge Saves Valuable Time!
Hi Can someone tell me how to round a decimal datatype value up to the nearest .5 in MS SQL. For example: 1.2 = 1.5 1.4 = 1.5 1.6 = 2.0 1.8 = 2.0 etc., etc. Many thanks in advance. Digga Sharing Knowledge Saves Valuable Time!
Oct 24, 2003 #2 Jamfool IS-IT--Management Apr 10, 2003 484 GB declare @a decimal(10,2) select @a = 1.34 SELECT ROUND(@a/.5,0) *.5 --or for two places SELECT ROUND(@a/.5,1) *.5 --Note 1.2 will be rounded down Upvote 0 Downvote
declare @a decimal(10,2) select @a = 1.34 SELECT ROUND(@a/.5,0) *.5 --or for two places SELECT ROUND(@a/.5,1) *.5 --Note 1.2 will be rounded down
Oct 24, 2003 1 #3 tlbroadbent MIS Mar 16, 2001 9,982 US Try this: SELECT Round(1.8*2.0 + 0.5, 0) / 2.0 If you want to get the best answer for your question read faq183-874 and faq183-3179. Terry L. Broadbent - DBA SQL Server Page: http://tlbroadbent.home.comcast.net/sql/sql_articles.htm Upvote 0 Downvote
Try this: SELECT Round(1.8*2.0 + 0.5, 0) / 2.0 If you want to get the best answer for your question read faq183-874 and faq183-3179. Terry L. Broadbent - DBA SQL Server Page: http://tlbroadbent.home.comcast.net/sql/sql_articles.htm
Oct 26, 2003 Thread starter #4 Digga Programmer May 11, 2001 84 GB Hi Guys Thanks for your responses. Jamfool, thank you, I had tried this and it didn't meet my needs as I wanted to round up, but thanks anyway. Terry, spot on mate, thank you very much. Digga Sharing Knowledge Saves Valuable Time! Upvote 0 Downvote
Hi Guys Thanks for your responses. Jamfool, thank you, I had tried this and it didn't meet my needs as I wanted to round up, but thanks anyway. Terry, spot on mate, thank you very much. Digga Sharing Knowledge Saves Valuable Time!