本文共 585 字,大约阅读时间需要 1 分钟。
方法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 =1SET @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)转载于:https://blog.51cto.com/13866219/2145274