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)
 Convert INT to decimal data type

Author  Topic 

konark
Yak Posting Veteran

60 Posts

Posted - 2009-07-16 : 19:53:59
An Table is having a column which is INT data type. Already running application .

Now I need to store a value 0.5 in that column which is INT.

Please advise what should I do .

Should i modify the datatype .if so , to what ??
The column is already having million of values already . Wont it affect ?

Chandragupta Mourya

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-07-16 : 20:05:02
You should change it to whatever it needs to be, probably a numeric. What type of values do you need it to store? You won't lose anything if you convert from int to float or numeric.



Jim
Go to Top of Page

konark
Yak Posting Veteran

60 Posts

Posted - 2009-07-17 : 00:55:52
the data type was INT andit used to store millions ofvalues .
But now one new requirement needs to store 0.5 which is decimal.

So i need to figure out .
1) TO What data type i need to change that column ?
2) Will there be any implicit data type conversion from INT to that data type , so that wewont have to change the procedures.

Chandragupta Mourya
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-17 : 01:00:25
1) you can use decimal data type.
2) yes. No issue for converting Integer to decimal
3) Did you also consider the output part ? Now your data type is decimal, can you application or stored procedure handle that ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

konark
Yak Posting Veteran

60 Posts

Posted - 2009-07-17 : 12:34:51
yes. No issue for converting Integer to decimal

Will it implicitly convert from INT to decimal .

previous Procedures are written as INT data type ?

Chandragupta Mourya
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-07-17 : 12:46:10
If your procedures are written as ints, they will be just fine in the database. You don't have to convert them to numeric before inserting. They will be implicitly converted from int to numeric However, if your procedures are written as ints, where does .5 come from?

Jim
Go to Top of Page

konark
Yak Posting Veteran

60 Posts

Posted - 2009-07-17 : 12:49:02
I said all old procedures are written to handle INT , as the column was INT before.

Now the new procedure 's requirement is to input values like 0.5 which is numeric .

So are you agreeing , it will implicitly convert from INT to Decimal /Numeric . We dont have to unload the data in production m before changing the data type ???

Chandragupta Mourya
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-17 : 13:56:04

quote:
Originally posted by konark

I said all old procedures are written to handle INT , as the column was INT before.

Now the new procedure 's requirement is to input values like 0.5 which is numeric .

So are you agreeing , it will implicitly convert from INT to Decimal /Numeric . We dont have to unload the data in production m before changing the data type ???

Chandragupta Mourya


if procedure has to input values like 0.5 then its parameter needs to be changed to be of type numeric or decimal
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2009-07-19 : 18:30:55
As well as what Visakh16 has pointed out, you'll also need to rebuild at least the clustered index to handle some of the page splits that will occur during the datatype change.

--Jeff Moden
"Your lack of planning DOES constitute an emergency on my part... SO PLAN BETTER! "
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row"

Go to Top of Page
   

- Advertisement -