方法1:
当出版社筛选条件为null,该如何写SQL呢?
1 DECLARE @publishers VARCHAR(50);
2 SELECT * FROM dbo.Book WHERE Publishers=ISNULL(@publishers,Publishers)
方法2:
declare @cinv varchar(50)
select * from inventory where 1=1 and (cInvName=@cinv or @cinv is null)
方法3:
DECLARE @name VARCHAR(100),@page INT =1
SET @name='张三'
DECLARE @sql VARCHAR(1000)
SET @sql='select * from myTable where 1=1'
IF @name IS NOT NULL
SET @sql=@sql+' and name='''+@name+''''--字符型注意引号个数
IF @page IS NOT NULL
SET @sql=@sql+' and page='+LTRIM(@page)--int类型注意转换为字符型
--PRINT @sql
EXEC(@sql)