日期:2014-05-18 浏览次数:20481 次
select * from sale where 1=1 and price between (case when price1=0 then price else price1 end) and (case when price2=0 then price else price2 end) and ...
------解决方案--------------------
DECLARE @price1 DECIMAL(12,5),@price2 DECIMAL(12,5) DECLARE @temp VARCHAR(500) DECLARE @sql VARCHAR(1000) SET @temp = '' set @sql = 'select * from sale where 1=1 ' IF Not (@price1 = 0 AND @price2 = 0) BEGIN SET @sql = @sql + ' where price between '+@price1+' and '+@price2 END EXEC(@sql) GO
------解决方案--------------------
拼接动态sql