I have a Laboratory-Test table with 120 columns all with datatype varchar
(which supposed to be FLOAT
) but these columns also contain characters like ^,*,A-Z,a-z
, commas, sentences with full stop "." at the end. I am using the following function to keep all the numeric values including ".".
The issue is this .
(dot ), if I use @KeepValues as varchar(50) = '%[^0-9]%'
then it will remove all the dots (e.g 1.05*L
become 105
) which is not something I want.
Could you please help me to resolved this would be very helpful or any alternative solution would be great
Create Function [dbo].[RAC]
(@Temp VarChar(1000))
Returns VarChar(1000)
AS
Begin
Declare @KeepValues as varchar(50) = '%[^0-9.]%'
While PatIndex(@KeepValues, @Temp) > 0
Set @Temp = Stuff(@Temp, PatIndex(@KeepValues, @Temp), 1, '')
Return @Temp
End
My T-SQL CASE
statement is :
,CASE WHEN LTRIM(RTRIM(DBO.RAC([INR]))) NOT IN ('','.')
THEN round(AVG(NULLIF(CAST(DBO.RAC([INR]) as FLOAT), 0)), 2)
END AS [INR]