SQL server + dynamic query + 'The data types nvarchar and bit are incompatible in the add operator.'
You're not converting [IsBirthdayVoucher]
to VARCHAR
, you're converting @var2
to VARCHAR
.
Try:
SET @sql = ('Select ' + @var1 + ' + Convert(varchar, ' + @var2 + ')
From [VoucherType]
Where [DeletedBy] is Null AND [AutoID] = 1')