Change is constant - 变化时唯一的永恒

实现多条件查询

DECLARE @name nvarchar(4000),@TotalRecord nvarchar,@countSql nvarchar(4000)
Set @name = 'Where 1=1'
set @countSql='SELECT * From AAAAABBBBB '+@name
execute sp_executesql @countSql

----------------------------------------------------------------------------------

SELECT * FROM AAAAABBBBB


declare
@para1 varchar(10)=1,
@para2 varchar(10)=null,
@para3 varchar(10)=null,
@para4 varchar(10)=null

DECLARE @sql varchar(8000)
SET @sql='SELECT * FROM AAAAABBBBB WHERE 1=1'
IF @para1 IS NOT NULL
SET @sql=@sql+' AND id='''+@para1+''''
EXEC(@sql)

 

 

posted @ 2016-04-13 09:17  人海灬  阅读(203)  评论(0编辑  收藏  举报