写了一个存储过程,带有多个参数,希望的是如果某个参数为空则不参与查询条件,但测试不成功不知道怎么回事
create proc
@vehicleid nchar(12),
@dn numeric(8,0)
as
select * from t1 where vehicleid like '%'+ isnull(@vehicleid,vehicleid) +'%' and dn = isnull(@dn,dn)没有提示错误,只是查询的结果不正确。
create proc
@vehicleid nchar(12),
@dn numeric(8,0)
as
select * from t1 where vehicleid like '%'+ isnull(@vehicleid,vehicleid) +'%' and dn = isnull(@dn,dn)没有提示错误,只是查询的结果不正确。
解决方案 »
- 请问一条sql语句
- 如何将SQL查询语句打包为一个EXE文件?
- 请问这条SQL 语句有错误吗? 为什么刚开始录入 '佳宝' 什么也查询不到,可录入 '夏利' 查询出来之后,再录入 '佳宝' 也能查询出来,不解 !!!
- 很简单的建库问题,新手求助!
- 问题呀~~~迷雾呀~~在线等呀!!!!!!
- 急 在线等!!谢谢
- sql server2005登陆的时候提示sa帐号被禁用
- SSIS package job erro
- 我要替换某字符字段中指定字符为新字符的T-SQL语句要怎么写?
- 初学SQL,请问高手这样的查询怎样写?
- 访问服务器有IP限制怎么办?
- Sql server2005分区视图,插入数据时会提示identity约束,无法插入
@vehicleid nchar(12),
@dn numeric(8,0)
as
if @dn is null or @dn=''
select * from t1 where vehicleid like '''%'+ @vehicleid +'%'''
end
else if @vehicleid is null or @vehicleid=''
select * from t1 where dn=@dn
end
@vehicleid nchar(12),
@dn numeric(8,0)
as
if @dn is null or @dn=''
begin
select * from t1 where vehicleid like '''%'+ @vehicleid +'%'''
end
else if @vehicleid is null or @vehicleid=''
begin
select * from t1 where dn=@dn
end
@vehicleid nchar(12),
@dn numeric(8,0)
as
select * from t1
where vehicleid like '''%'+ isnull(@vehicleid,vehicleid) +'%''' and dn = isnull(@dn,dn)你再试试
--sql2008 执行的
declare @a nchar(12),
@b nvarchar(10)
set @a='1'
set @b='2'
print @a+'==='
print @b+'==='
--执行结果
--1 ===
--2===
--楼主悟出点什么木有?
(
@vehicleid varchar(12),
@dn numeric(8,0)
)
as
select * from t1 where vehicleid like '%'+ isnull(@vehicleid,vehicleid) +'%' and dn = isnull(@dn,dn)