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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 truncate

Author  Topic 

Jason_D
Starting Member

11 Posts

Posted - 2002-07-05 : 16:20:37
Hey Dudes and Dudettes

I'm having some trouble with truncating some numbers.

I would like to do the following:

-12.123456 --> -12.123
12.123456 --> 12.123
123.123456 --> 123.123

I've gotten this so far:
number=left(round(number,3.3),6)

but this only works for numbers in the form xx.xxxxxx

It's easy to do "if" statements, but I am actually performing this during the SELECT statement:
eg. select number=left(round(number,3.3),6)

peace

nr
SQLTeam MVY

12543 Posts

Posted - 2002-07-05 : 17:06:32
have you tried converting to decimal?
And you can use a case statement in a select.
==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.

Edited by - nr on 07/05/2002 17:07:29
Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2002-07-06 : 08:27:24
select abs(convert(decimal(16,2),round(@number,3.2)))



-------------------------
What lies behind you and what lies ahead of you are small matters compared to what lies within you.-Ralph Waldo Emerson
Go to Top of Page

Jason_D
Starting Member

11 Posts

Posted - 2002-07-08 : 10:04:23
Thanks guys

The following worked for me. My numbers are in the format decimal (9.7)

number=stuff(round(number, 3.3), len(number)-3, 4,'')

Go to Top of Page

MakeYourDaddyProud

184 Posts

Posted - 2002-07-08 : 10:17:53
Take a look at CEILING and FLOOR T-SQL functions to further rearmour your knowledge, they might also help at some point...

Daniel Small MIAP
www.danielsmall.com IT Factoring
Go to Top of Page
   

- Advertisement -