查询时间段问题
declare @str varchar(1000),@SD smalldatetime,@ED smalldatetime
set @SD= '2007/07/01 '
set @ED= '2007/07/31 '
set @str= 'select * from tb '
select @str=@str+ ' where Date between '+@SD+ ' and '+@ED+ ' '
exec(@str)
上述语句查询不出来该时间段的数据,数据显示为空
请问怎么样才能查出此时间段的数据
------解决方案--------------------declare @str varchar(1000),@SD smalldatetime,@ED smalldatetime
set @SD= '2007/07/01 '
set @ED= '2007/07/31 '
set @str= 'select * from tb '
select @str=@str+ ' where Date between ' ' '+ Convert(Varchar, @SD, 120) + ' ' ' and ' ' '+Convert(Varchar, @ED, 120) + ' ' ' '
exec(@str)