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 |
|
KabirPatel
Yak Posting Veteran
54 Posts |
Posted - 2007-03-09 : 07:03:35
|
| Hi,I have a table (TableA) as follows:ColumnA ColumnB----------------------Value01 R01Value01 R02Value02 R04I have another table as follows (TableB):ColumnA ColumnB----------------------Value02 R01Value01 R03Value01 R01I want to insert into TableA all the values from TableB that do not currently exist in TableA. I want to do this without using a cursor.I dont want to do this with an "IF EXISTS" either as this is slow.I tried something like the following: INSERT INTO [TableA]([ColumnA], [ColumnB]) SELECT [ColumnA], [ColumnB] FROM [TableB] LEFT JOIN [TableA] ON [TableB].[ColumnA] = [TableA].[ColumnA] AND [TableB].[ColumnB] = [TableA].[ColumnB] WHERE [TableA].[ColumnB] IS NULLbut is doesnt seem to work.Any ideas?Thanks in advance.Kabir |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-09 : 07:06:17
|
| insert tablea (columna, columnb)select tb.columna, tb.columnb from tableb as tbleft join tablea as ta on ta.columna = tb.columna and ta.columnb and tb.columnbwhere ta.columna is nullPeter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-09 : 07:07:13
|
| You have to prefix your column names with table names, just as the error message tells you.Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|