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)