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 2008 Forums
 Other SQL Server 2008 Topics
 Alter Column DataType in SMO

Author  Topic 

mistryvipulh
Starting Member

4 Posts

Posted - 2008-11-15 : 08:34:53
hello friends

i have created a table in database using SMO classes.

now i want to change datatype of a column from varchar to numeric.

i m specifying scale and precision values then also it gives me error
"Length or precision specification 0 is invalid (Microsoft Sql Server Error : 1001)

Plz can any help me to solve this problem

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-15 : 13:16:12
how were you defining numeric column?
Go to Top of Page

mjc
Starting Member

1 Post

Posted - 2010-11-17 : 12:31:41
Didn't see any follow up on this, so posting one possible solution.

It seems that when altering a column to the Decimal type, the following works ...

Column col = table.Columns[columnName];
col.DataType = Smo.DataType.Decimal(scale, precision);

// for some reason, if you leave it at that, the scale and precision don't take and the error described in the previous post occur
// to get past the error, you can then reset the scale and precision
col.DataType.NumericPrecision = precision;
col.DataType.NumericScale = scale;
col.Alter();
Go to Top of Page
   

- Advertisement -