Varchar variable is not working in WHERE clause

Because when you declare, default varchar length is 1. So @MyVarchar ends up being 'A'.

This is different to cast(something as varchar), where default length is 30.

The right thing is

DECLARE @MyVarchar varchar(10) = 'ABCDEF';

where 10 is the length of the column in the table.

Leave a Comment