Hi,
I'm using the following code to convert a varchar to a float in a trigger.
declare @.acre varchar (6)
set @.acre_size = 0.0
select @.acre = plotsizeacre
from inserted
declare @.num int
select @.num = isnumeric (@.acre)
if @.num = 1
set @.acre_size = @.acre
This normally works fine, but I'm getting errors if the plotsizeacre field is 1,75
Casting to a float or converting to a float also gives errors.
Any ideas how to solve this problem? (The field would normally be filled in properly, eg 1.75).
Thanks in advance,
Ian
You cannot use ISNUMERIC to do strick checking. This function will return 1 for value that can be converted to any of the integer, numeric, float and money data types. The value '1,75' can be converted to money but not float. Your best option is to chnage the schema and modify the column to float. This will require modifications from the client side also to make sure that the value that user enters is typed accordingly. If you have to keep the varchar data type then you will have to perform the cleaning of the value yourself - meaning you have to check for bad formats and convert appropriately or error out gracefully.
No comments:
Post a Comment