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 2005 Forums
 Transact-SQL (2005)
 Decimal Question

Author  Topic 

hydtohou
Starting Member

24 Posts

Posted - 2007-11-09 : 13:12:42
Hi
This might be simple but I'm in a hurry so here is the question.
I have something like this
declare @col decimal(7,4)
set @col = 123.45

select @col
it assigns it as 123.4500 which is fine

But, Can I take out the extra 00's ; because the Input that I get might have something like 1234.56; at this point Input is correct but when I load to SQL table it will fail because SQL Server adds 00's
and the precision would become 8 and fail

I don't know whether I can change the datatype to decimal(10,4) for example.


Regards,

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-11-09 : 13:29:51
Why not change it to (7,2) instead?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

hydtohou
Starting Member

24 Posts

Posted - 2007-11-09 : 13:31:15

I'm not sure I can do that either. It's not in my hands.

quote:
Originally posted by DonAtWork

Why not change it to (7,2) instead?

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-09 : 13:41:03
Not even

SELECT CAST(Col1 AS DECIMAL(7, 2))
FROM Table1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

hydtohou
Starting Member

24 Posts

Posted - 2007-11-09 : 13:49:53
I'm trying to insert not select

quote:
Originally posted by Peso

Not even

SELECT CAST(Col1 AS DECIMAL(7, 2))
FROM Table1



E 12°55'05.25"
N 56°04'39.16"


Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-09 : 13:55:48
How on earth can some extra zeros fail an insert to a decimal field?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-09 : 13:56:27
INSERT NewTable (NewCol)
SELECT CAST(OldCol AS DECIMAL(7, 2))
FROM OldTable



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -