October 1, 2010 at 2:03 pm
I'm trying to perform a simple insert into an existing table Ship_b and I only want records from table Ship_a that have different Load_# from records that are already in table Ship_b. Looks like my where statement should get rid of any of the records from Ship_a that are the same as the records in Ship_b.
INSERT INTO [Ship_b]
([Load_id]
,[Ship_id]
,[Billing address])
SELECT ([Load_id]
,[Ship_id])
,[Billing address]
FROM [Ship_a]
WHERE [Ship_b].[Load_id] <> [Ship_a].[Load_id]
October 1, 2010 at 2:41 pm
May I direct your attention to the Merge T-SQL statement, which appears to be the method you would choose to do what you want to do.
October 1, 2010 at 2:46 pm
rwyatt292 (10/1/2010)
I'm trying to perform a simple insert into an existing table Ship_b and I only want records from table Ship_a that have different Load_# from records that are already in table Ship_b. Looks like my where statement should get rid of any of the records from Ship_a that are the same as the records in Ship_b.
How about something like...
INSERT
INTO [Ship_b]
([Load_id]
,[Ship_id]
,[Billing address])
SELECT ([Load_id]
,[Ship_id])
,[Billing address]
FROM [Ship_a]
WHERE [Ship_a].[Load_id] not in (select X.[Load_id]
from [Ship_b] X
where [Ship_a].[Load_id] = X.[Load_id])
_____________________________________
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at Amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.October 1, 2010 at 3:48 pm
bitbucket-25253 (10/1/2010)
May I direct your attention to the Merge T-SQL statement, which appears to be the method you would choose to do what you want to do.
I'll have to look into using MERGE - thanks! 😎
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
October 3, 2010 at 11:54 am
thanks for the helpful info
October 3, 2010 at 11:54 am
thanks for the helpful info
October 3, 2010 at 11:55 am
Paul thanks for the help
October 3, 2010 at 8:25 pm
rwyatt292 (10/3/2010)
Paul thanks for the help
Glad to help.
_____________________________________
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at Amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply