August 15, 2007 at 11:34 am
Hello,
Is there a way to programatically change all fields in all tables in a db from data type float to decimal?
Thank you
August 15, 2007 at 12:38 pm
the way to do it is with the ALTER TABLE ALTER COLUMN command:
example:
create table test (testid int,testcol float);
exec sp_help test;
alter table test alter column testcol decimal;
exec sp_help test;
drop table test;
now to do it to every FLOAT column in your database, you have to find them and run the results of this query after reviewing them for accuracy:
select object_name(id) As TableName,
name as Columnname,
TYPE_NAME(xtype) AS datatype,
'ALTER TABLE ' + object_name(id) + ' ALTER COLUMN ' + name + ' decimal' AS SQL
from syscolumns
where TYPE_NAME(xtype)='float'
Lowell
August 16, 2007 at 7:49 am
Hi
i think this will help you
check the system table (information_schema.tables) and apply alter table commend
August 16, 2007 at 6:35 pm
Thank you both for the very informative descriptions!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply