I would like to retrieve data from a database which is of type varchar e.g
size: 100mm,100 ,20mm, 500, 450mm and trim ‘mm’ from the string and than convert it to integer and than compare from from the same column: e.g @Size1 <= size_column and @size2 >= size_column:
Here’s my query to trim and convert, but its giving me errors.
SELECT DEVICE_NO,
CASE [Rms_Size]
WHEN
(SELECT RMS_SIZE FROM DW_DATA.DBO.DIM_DEVICE WHERE
Ltrim(Rtrim(Rms_Size)) LIKE '%mm')
THEN
(SELECT SUBSTRING(Rms_Size,1,LEN(rms_size)-2)
FROM DW_DATA.DBO.DIM_DEVICE
where Ltrim(Rtrim(Rms_Size)) LIKE '%mm')
ELSE
RMS_SIZE
END
AS RMS_SIZE
FROM
DW_DATA.DBO.DIM_DEVICE
Try this -: