sql isnumeric(2,000.00)=1 but isfloat(2,000.00) errors Error converting data type varchar to float.

select isnumeric('20,000.000') returns 1
select convert(float, '20,000.000') raises an errorĀ Error converting data type varchar to float.

You can’t write a isfloat() function, because try-catch is a side effect.

Here’s a snippet to walk thru your data to find duff values

declare c cursor for
select chillirecipedetailid, amount_or from tblAbRecipes
open c
declare @id int, @val nvarchar(100)
fetch next from c into @id, @val
while @@FETCH_STATUS=0
begin
 begin try
 declare @f float
 set @f = convert(float,@val)
 end try
 begin catch
 print 'duff value at ' + convert(nvarchar(20),@id) + ': ' + @val
 end catch;
 fetch next from c into @id, @val
end;
close c
deallocate c

select isnumeric('20,000.000')
select convert(float, '20,000.000')

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Website by Daneswood