October 19, 2006 at 9:10 am
Bleow is sql for data type change for '82.'. Only the last sql fail, whcih mean you can not change a numeric and decial into int directly when you can change it to decial then to int. Interesting, but i don't know why.
print isnumeric('82.')
print cast('82.' as decimal)
print cast(cast('82.' as decimal) as int)
print cast('82.' as int)
1
82
82
Server: Msg 245, Level 16, State 1, Line 5
Syntax error converting the varchar value '82.' to a column of data type int.
October 19, 2006 at 9:39 am
No. You are not converting NUMERIC into INT. You are converting VARCHAR into INT, and that's why it does not work. Integer data don't include any decimal separators, if you convert something to integer from a string, the string may not contain other characters except numbers (and + or - sign).
ISNUMERIC behaves a bit strange (though understandable, once you find out why) and is not a good way to test numbers althogether. Contrary to what you may expect, it does not tell you whether the string can be converted to a specific type of number or not... see BOL :
A return value of 1 guarantees that expression can be converted to one of these numeric types.
It does not say "to any of these types", but to one of these types. That is, some can be converted to integer, some to float... etc.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply