In SQL Server (2018 I think? I don't know how to tell) my variable isn't working in WHERE
clauses for NVARCHAR.
The comparison should return values but it returns nothing. If I just type the declared text in manually it suddenly works and returns values. There's no logical reason this should be any different, the types are both NVARCHARS. It is working for dates and numbers for me.
The following SQL Server code works properly and returns results:
SELECT * FROM table WHERE Column = 'text'
The following code fails however by coming up empty when I use an initial declare statement:
DECLARE @Class AS NVARCHAR = 'text'
SELECT * FROM table WHERE Column = @Class
I can't get the variable to work in the WHERE
clause even though I have confirmed that column is an NVARCHAR
. Other parameters I'm declaring work just fine it just seems to be NVARCHAR
giving me issues.
Is there something I'm missing?