Thursday, March 29, 2012

Combining Tables...

Hello everyone,

I'm having problems transfering data. I don't even know if this is even possible, but this is what I'm trying to do. I have two tables: ZipRegionUps, ZipRegionUsps. Both tables have the same two columns: Zip, Region.

I want to combine the two. Having one table ZipRegion with three columns: Zip, UpsRegion, Usps Region. I've tried everything I can think of, but no luck. Here's the most sensible Stored Procedure I have tried:

If I wasn't very clear with my explanation, I'm hoping the procedure will clear things up:


CREATE PROCEDURE CMRC_Databases_DataTransfer
AS
DELETE FROM CMRC_ZipRegionTest

INSERT INTO CMRC_ZipRegionTest
(
Zip,
UpsRegion,
UspsRegion
)
SELECT
CMRC_ZipRegionUps.Zip,
CMRC_ZipRegionUps.UpsRegion,
CMRC_ZipRegionUsps.UspsRegion
FROM
CMRC_ZipRegion,
CMRC_ZipRegionUsps
GO

Is there any way to do this? Or do I have to manually enter all the entries?

Any help would be great. Thank you.

-AlecUnion is what you're looking man.


SELECT

CMRC_ZipRegionUps.Zip,

CMRC_ZipRegionUps.UpsRegion,

CMRC_ZipRegionUsps.UspsRegion

FROM

CMRC_ZipRegionUsps

UNION

SELECT

CMRC_ZipRegion.Zip,

CMRC_ZipRegion.UpsRegion,

CMRC_ZipRegion.UspsRegion

FROM

CMRC_ZipRegion

GO

No comments:

Post a Comment