I have column sql variant, which has the following meanings: 100, 150, D1
I'm trying to convert all numbers in the columns into letters (such as D1
) according to specific logic in case when. But 150
has spaces and the CASE WHEN
doesn't work.
Here's the query I'm using:
Select *,
Case When LTrim(Cast(AttributeValue As NVarchar(Max))) Between 0 And 200 Then 'D1'
Else 'Other'
End
From MyTable As SCR With (NoLock);
I tried the following
LTRIM(CAST column AS VARCHAR(MAX))
but now I get error:
Conversion failed when converting the nvarchar value 'D1' to data type int
How can I remove spaces from sql_variant?