Can anybody explain this? Theoretically both are the same query but they give different answers.
a)
declare @date varchar(10)
set date = '03/02/2013'
select count(*) from table1 where (from <= @date) and (@date <= to)
b)
declare @date varchar(10)
set date = '03/02/2013'
set @sqlstring = 'select count(*) from table1 where (from <= ' + @date + ') and (' + @date + ' <= to)'
exec sp_executeSql @sqlstring
The first set of sentences gives '2' as a result, and this is the correct answer, but in the second set of sentences, I have the same query executed dynamically through a string, but the answer is '0'.