| Author |
Topic |
|
IA
Starting Member
9 Posts |
Posted - 2007-08-22 : 04:01:49
|
| Hi all,I'm trying to update a table as follows:Where in the table i got.OldCol; a varcharNewCol; FloatUpdate tbl set newCol = cast(float,oldcol)Where isNumeric(oldcol) =1But it give me the follwong error:Error converting data type from Varchar to Float.Any suggestion? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-08-22 : 04:10:15
|
ISNUMERIC is not reliable, becuase it allows some characters in the numeric check.What kind of varchar "numeric" do you have? Are they all supposed to be integers? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-22 : 04:17:34
|
| Instead of Where isNumeric(oldcol) =1useWhere oldcol not like '%[^0-9.]%'MadhivananFailing to plan is Planning to fail |
 |
|
|
IA
Starting Member
9 Posts |
Posted - 2007-08-22 : 04:23:12
|
NO, not integers but with decimalquote: Originally posted by Peso ISNUMERIC is not reliable, becuase it allows some characters in the numeric check.What kind of varchar "numeric" do you have? Are they all supposed to be integers? E 12°55'05.25"N 56°04'39.16"
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-22 : 04:26:28
|
quote: Originally posted by IA NO, not integers but with decimalquote: Originally posted by Peso ISNUMERIC is not reliable, becuase it allows some characters in the numeric check.What kind of varchar "numeric" do you have? Are they all supposed to be integers? E 12°55'05.25"N 56°04'39.16"
Try my suggestionCan you post some sample data?MadhivananFailing to plan is Planning to fail |
 |
|
|
IA
Starting Member
9 Posts |
Posted - 2007-08-22 : 04:41:10
|
I used what you suggested, but it does not update any record.0 Record updatedSample data:4,6510,59,660,0quote: Originally posted by madhivanan Instead of Where isNumeric(oldcol) =1useWhere oldcol not like '%[^0-9.]%'MadhivananFailing to plan is Planning to fail
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-22 : 04:50:02
|
| So did you store comma sepeated values in a column?MadhivananFailing to plan is Planning to fail |
 |
|
|
IA
Starting Member
9 Posts |
Posted - 2007-08-22 : 04:59:44
|
| As it show in samples |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-22 : 05:32:48
|
| Well. which value do you want to take? eg from 4,65 do you need 4 or 65?MadhivananFailing to plan is Planning to fail |
 |
|
|
IA
Starting Member
9 Posts |
Posted - 2007-08-22 : 05:36:08
|
| I need all as it's in the oldcol. But anyay it seems imposible like that. I remove the comma then it works. |
 |
|
|
sbalaji
Starting Member
48 Posts |
Posted - 2007-08-22 : 06:23:54
|
| Update tbl set newCol = cast(replace(oldcol,',','.') as float)Where isNumeric(oldcol) =1i think this should work,I presume u r using comma separator to denote decimal values instead of dot. |
 |
|
|
IA
Starting Member
9 Posts |
Posted - 2007-08-22 : 06:31:10
|
| Yes, it did work, thank you very much. Cheers |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-08-22 : 06:33:07
|
quote: Originally posted by IA Yes, it did work, thank you very much. Cheers
Dont store formatted data in a tableMadhivananFailing to plan is Planning to fail |
 |
|
|
|