给你个参考吧:把要执行的语句写成sql字符串变量,执行变量即可
declare @sql varchar(1000)
declare @filter varchar(400)
declare @orderby varchar(50)
set @sql = ' select * from 你的表 '
set @filter = ' where 1=1 '
set @orderby = ' order by id desc '
if ....
set @filter = @filter + ' and 条件1 '
if ...
set @filter = @filter + ' and 条件2 '
-- 执行sql
exec( @sql + @filter + @orderby )
select * from table_name t where t.table_column=:B1