哪位高手帮小弟我看看这个存储过程错在哪啊感激
谁帮我看看这个存储过程错在哪啊?感激
主要是实现查询功能的存储过程,提示说IF附近错误,谁帮忙看看啊!
CREATE PROCEDURE dbo.C_PhoneQuery (@no varchar(20)=null,@compid varchar(3)=null,@id int=null)
if @id is not null
select carid,compid,carno,cartype,engineno,frameno,factory,seatorton,runedkm,buydate ,carstatus, carowner, remark from C_car where carid=@id
else
if @compid is not null and @compid <> ' '
select a.carid 编号,b.compname 单位名称,a.carno 车牌号码,a.cartype 车辆类型,a.engineno 发动机号码,a.frameno 底盘号码,a.factory 生产厂家,a.seatorton 座位,a.renedkm 已行驶里程,a.carowner 车主名称,a.remake 备注 from C_Car a
left outer join company b on a.compid = b.compid
where a.compid = @compid
else
if @no is not null and @no <> ' '
select a.carid 编号,b.compname 单位名称,a.carno 车牌号码,a.cartype 车辆类型,a.engineno 发动机号码,a.frameno 底盘号码,a.factory 生产厂家,a.seatorton 座位,a.renedkm 已行驶里程,a.carowner 车主名称,a.remake 备注 from C_Car a where a.carno=@no
else
if @no is not null and @no <> ' ' and @compid is not null and @compid <> ' '
select a.carid 编号,b.compname 单位名称,a.carno 车牌号码,a.cartype 车辆类型,a.engineno 发动机号码,a.frameno 底盘号码,a.factory 生产厂家,a.seatorton 座位,a.renedkm 已行驶里程,a.carowner 车主名称,a.remake 备注 from C_Car a
left outer join company b on a.compid = b.compid
where a.compid =@compid and a.carno=@no
else
select a.carid 编号, b.compname 单位名称,a.carno 车牌号码,a.cartype 车辆类型,a.engineno 发动机号码,a.frameno 底盘号码,a.factory 生产厂家,a.seatorton 座位,a.renedkm 已行驶里程,a.carowner 车主名称,a.remake 备注 from C_Car a
left outer join company b on a.compid = b.compid
go程,a.carowner 车主名称,a.remake 备注 from C_Car a
left outer join company b on a.compid = b.compid
GO
------解决方案--------------------
把if @no is not null and @no <> ' ' and @compid is not null and @compid <> ' '写在第一个else后面,不然始终不会出现这满足这个件条的结果
主要是实现查询功能的存储过程,提示说IF附近错误,谁帮忙看看啊!
CREATE PROCEDURE dbo.C_PhoneQuery (@no varchar(20)=null,@compid varchar(3)=null,@id int=null)
if @id is not null
select carid,compid,carno,cartype,engineno,frameno,factory,seatorton,runedkm,buydate ,carstatus, carowner, remark from C_car where carid=@id
else
if @compid is not null and @compid <> ' '
select a.carid 编号,b.compname 单位名称,a.carno 车牌号码,a.cartype 车辆类型,a.engineno 发动机号码,a.frameno 底盘号码,a.factory 生产厂家,a.seatorton 座位,a.renedkm 已行驶里程,a.carowner 车主名称,a.remake 备注 from C_Car a
left outer join company b on a.compid = b.compid
where a.compid = @compid
else
if @no is not null and @no <> ' '
select a.carid 编号,b.compname 单位名称,a.carno 车牌号码,a.cartype 车辆类型,a.engineno 发动机号码,a.frameno 底盘号码,a.factory 生产厂家,a.seatorton 座位,a.renedkm 已行驶里程,a.carowner 车主名称,a.remake 备注 from C_Car a where a.carno=@no
else
if @no is not null and @no <> ' ' and @compid is not null and @compid <> ' '
select a.carid 编号,b.compname 单位名称,a.carno 车牌号码,a.cartype 车辆类型,a.engineno 发动机号码,a.frameno 底盘号码,a.factory 生产厂家,a.seatorton 座位,a.renedkm 已行驶里程,a.carowner 车主名称,a.remake 备注 from C_Car a
left outer join company b on a.compid = b.compid
where a.compid =@compid and a.carno=@no
else
select a.carid 编号, b.compname 单位名称,a.carno 车牌号码,a.cartype 车辆类型,a.engineno 发动机号码,a.frameno 底盘号码,a.factory 生产厂家,a.seatorton 座位,a.renedkm 已行驶里程,a.carowner 车主名称,a.remake 备注 from C_Car a
left outer join company b on a.compid = b.compid
go程,a.carowner 车主名称,a.remake 备注 from C_Car a
left outer join company b on a.compid = b.compid
GO
------解决方案--------------------
把if @no is not null and @no <> ' ' and @compid is not null and @compid <> ' '写在第一个else后面,不然始终不会出现这满足这个件条的结果