Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rob41
Yak Posting Veteran
67 Posts |
Posted - 2010-10-01 : 15:54:03
|
| 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_#] ,[Ship_#] ,[Billing address])SELECT ([Load_#] ,[Ship_#]) ,[Billing address] FROM [Ship_a]WHERE [Ship_b].[Load_#] <> [Ship_a].[Load_#] |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-01 : 21:32:46
|
| [code]INSERT INTO [Ship_b] ([Load_#], [Ship_#],[Billing address])SELECT a.[Load_#], a.[Ship_#], a.[Billing address]FROM [Ship_a] aLEFT JOIN [Ship_b] bOn a.[Load_#] = b.[Load_#]WHERE b.[Load_#] IS NULL;[/code] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-02 : 03:05:12
|
alsoINSERT INTO [Ship_b] ([Load_#], [Ship_#],[Billing address])SELECT a.[Load_#], a.[Ship_#], a.[Billing address]FROM [Ship_a] aWHERE NOT EXISTS(SELECT 1 FROM [Ship_b] bWHERE a.[Load_#] = b.[Load_#]) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
rob41
Yak Posting Veteran
67 Posts |
Posted - 2010-10-03 : 13:59:09
|
Russel and visakh16 thanks for taking the time to help me your solutions worked and your help is greatly appreciated!!!!  |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-10-03 : 22:59:28
|
Glad to help |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-04 : 09:34:42
|
| welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|