我有以下存储过程:
create procedure Get_CarInfo
@PlateNo nvarchar(10)
as
select Administration.City AS AdCity
from Administration
where Administration.AdministrationNo = (select Car.AdministrationNo from Car WHERE car.PlateNo = @PlateNo)
select car.Brand, car.model, car.Color, car.AdministrationNo, car.InsuranceNo, car.RegistrationExp
from Car
where car.PlateNo = @PlateNo
我想做的是检索汽车信息(品牌,颜色等等),但Car表中的问题有管理号码字段,我想根据管理号码检索管理城市在管理表中。
这是Car的表格:
PlateNo - 品牌 - 颜色 - 模型 - AdministrationNo - InsuranceNo - RegistrationExp
行政管理表:
AdministrationNo - City
我放了两个select语句,但它没有用。请提出任何建议!!
答案 0 :(得分:2)
您不需要执行此操作的过程,以下查询将执行此操作:
select
car.Brand,
car.model,
car.Color,
car.AdministrationNo,
car.InsuranceNo,
car.RegistrationExp,
Administration.City
from Car
left join Administration
ON Administration.AdministrationNo = Car.AdministrationNo
where car.PlateNo = xxx
xxx
是车牌号