Here's an example of what I'm playing with:
update TestTable
set IntValue = Cast(StringValue, as int)
flag =
BEGIN TRY
0
END TRY
BEGIN CATCH
1
END CATCH
I'm trying to take a string value holding an integer and populate an integer field with that value. But, every so often, the string value does not contain an integer (e.g. '13.9" or "CA"). That error would cause the entire column UPDATE to be rolled back. i'm trying to get around it with some kind of "TRY CATCH" construct but I don't believe it can work.
What would you suggest?
Barkingdog
No, you are right this won′t work. For me, the best Exception handling is to prevent exceptions, in your case check the value for being numeric, there is a function ISNUMERIC which can do that for you. But be careful with that function, because it checks for currency numeric only, so the value "$" which is part of a currency expression will also evaluate to true.
See more details on the site: http://www.aspfaq.com/show.asp?id=2390
HTH, jens Suessmeyer.
http://www.sqlserver2005.de
No comments:
Post a Comment