July 5, 2005 at 1:45 pm
I'm having trouble casting a CHAR field to an INT. I keep getting a syntax error message:
Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value 'K' to a column of data type int.
Here is the code:
Update tblIntelecDownload
Set CRSC_3_PLACE_NUM = 1
WHERE CAST(SCRCTG AS INT) = 3
Can someone please tell me what I'm doing wrong.
Thanks in advance!
July 5, 2005 at 2:01 pm
Can you do it that way?
Update tblIntelecDownload
Set CRSC_3_PLACE_NUM = 1
WHERE SCRCTG = '3'
July 5, 2005 at 2:01 pm
There may be rows with nonumeric values in the column in question.
check
SELECT SCRCTG, * FROM tblIntelecDownload
WHERE
ISNUMERIC(SCRCTG) = 0
Good idea Remi
Regards,
gova
July 5, 2005 at 2:03 pm
Gonna have to learn to type slower
follow up question :
Are you casting to int because you have values like '03' or '0003'?
July 5, 2005 at 2:11 pm
Man...I feel so stupid! Premature senior moment. It never crossed my mind to just put my criteria in quotes.
Thanks Remi
July 5, 2005 at 2:25 pm
Gives a chance to use an index seek too .
July 6, 2005 at 4:49 am
beware
"SELECT SCRCTG, * FROM tblIntelecDownload WHERE ISNUMERIC(SCRCTG) = 0"
won't deal with some 'char' data...ie numbers which can be represented using "scientific notation" ....particularly D and E
July 6, 2005 at 5:36 am
It's better to use LIKE and wildcards instead of ISNUMERIC() because LIKE + wc gives you more control.
If you want to find values with numerics only:
SELECT myColumn
FROM myTable
WHERE myColumn NOT LIKE '%[^0-9]%'
If you want to find values that have any chars but numerics only:
SELECT myColumn
FROM myTable
WHERE myColumn LIKE '%[^0-9]%'
/Kenneth
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply