Stored procedure code listed below. This trimmed down version of a stored procedure queries for a city from a zip code database and inserts the original data if no zip code is found or inserts the city from the zip code database if a zip code is found. Is there a way to insert the return data from the first query and not have to perform the second query to supply the city when the zip code is found?
CREATE PROCEDURE transform_as400_data AS
INSERT INTO DevelopmentWarehouse.dbo.Contract
(PurchaserCity)
SELECT
PurchaserCity = case (SELECT city FROM ZipCode.dbo.ziplist5 where zip = PurchaserZip)
WHEN Null then PurchaserCity
ELSE (SELECT City FROM ZipCode.dbo.ziplist5 where zip = PurchaserZip)
END
FROM DevelopmentStaging.dbo.Contract
GO
CREATE PROCEDURE transform_as400_data AS
INSERT INTO DevelopmentWarehouse.dbo.Contract
(PurchaserCity)
SELECT
PurchaserCity = case (SELECT city FROM ZipCode.dbo.ziplist5 where zip = PurchaserZip)
WHEN Null then PurchaserCity
ELSE (SELECT City FROM ZipCode.dbo.ziplist5 where zip = PurchaserZip)
END
FROM DevelopmentStaging.dbo.Contract
GO