| Author |
Topic |
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2008-02-21 : 04:14:52
|
| i'm trying to update this statement, but the problem is col20 is nchar(20 datatype and col10 is decimal(5,2).i'm using the above statement.i'm getting error.Error converting data type nvarchar to numeric. please guide me.UPDATE TABLE17 SET COL10=cast(COL20 as decimal(5,2))GOVinodEven you learn 1%, Learn it with 100% confidence. |
|
|
PeterNeo
Constraint Violating Yak Guru
357 Posts |
Posted - 2008-02-21 : 04:20:48
|
| Try using ISNUMERIC(COL20) = 1 in where clause |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-21 : 04:21:36
|
| You should make sure that COL20 has only numeric dataUPDATE TABLE17 SET COL10=cast(COL20 as decimal(5,2))WHERE COL20 not like '%[^0-9]%'MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-21 : 04:50:02
|
quote: Originally posted by PeterNeo Try using ISNUMERIC(COL20) = 1 in where clause
Note that ISNUMERIC() is not reliableSelect data from(select '123' as dataunion allselect '12d3') as twhere ISNUMERIC(data)=1MadhivananFailing to plan is Planning to fail |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2008-02-21 : 05:12:33
|
| thank you very muchVinodEven you learn 1%, Learn it with 100% confidence. |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2008-02-21 : 05:28:55
|
| SORRY for not conveying completly...actually, if col20 ='y', then col10 should be 1. if col20='N', then col10 should be 2.i've written like this....please correct meUPDATE TABLE17 SET COL10= CASE WHEN COL20='Y' THEN '1' ELSE COL20='N' THEN '2' else '0'col20 is nchar(2) datatype and col10 is decimal(5,2).sorry for not giving complete information.help me in this regard |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-21 : 05:54:01
|
| TryUPDATE TABLE17 SET COL10= CASE WHEN COL20='Y' THEN '1' WHEN COL20='N' THEN '2' else '0' ENDMadhivananFailing to plan is Planning to fail |
 |
|
|
sunsanvin
Master Smack Fu Yak Hacker
1274 Posts |
Posted - 2008-02-22 : 01:00:42
|
| Thankyou very mcuh Madhi...it worked for meVinodEven you learn 1%, Learn it with 100% confidence. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-22 : 01:38:14
|
| Also If col10 would have only 0,1 or 2, then change the datatype of Col10 to tinyintMadhivananFailing to plan is Planning to fail |
 |
|
|
|