Reputation: 2140
I have the following stored procedure:
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
What I would like to do is to retrieve the car information (brand, color, .. etc) but the problem in the Car table there is administration number field and I would like to retrieve the administratrion city based on the administration no in the administration table.
Here is the table of Car:
PlateNo - Brand - Color - Model - AdministrationNo - InsuranceNo - RegistrationExp
The Administration table:
AdministrationNo - City
I put two select statements but it didn't work. Any suggestions please !!
Upvotes: 0
Views: 326
Reputation: 8090
You do not need a procedure to achieve this, the following query will do :
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
Where xxx
is the car plate number
Upvotes: 2