I am trying to make a conversion script that takes a measurement and converts it to a different unit.
Example centimeter to milometers. I don’t want to make the field case sensitive in case someone would put Inch or inch in @p2 I want it to return the same value but certain values need to be case sensitive ‘mm’ could be Mega meters or Millimeters. Therefore I was trying to use a select statement in the then section of the where clause an it is giving me Incorrect syntax near the keyword 'select'.
Below is the code
declare @P1 VARCHAR(max) –- value of the measurement
declare @P2 VARCHAR(max) –- original unit
declare @P3 VARCHAR(max)—new unit
DECLARE @pos INT;
DECLARE @cleanInput VARCHAR(100);
set @P1 = '12'
set @P2 = 'm'
set @P3 = 'inch'
SET @cleanInput ='';
SET @pos = 1;
WHILE @pos <= Len(@P1)
SET @cleanInput= @cleanInput + CASE WHEN Isnumeric(Substring(@P1,
= 1 THEN Substring(
@p1, @pos, 1) ELSE '' END;
SET @pos = @pos + 1;
--SET @cleanInput = Replace(@CleanInput, ',', '');
SET @cleanInput = Replace(@CleanInput, '$', '');
set @cleanInput = case
when @P2 = 'mm' then select ( cast (@cleanInput as float) *multiplier
from [L_Conversion_Table ]
where ASCII( type) = ASCII(@P2))