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 |
|
sogorman
Starting Member
5 Posts |
Posted - 2010-12-19 : 16:25:30
|
| I have two tables and I want to update T1 with all the columns and data from T2 (same table structure just different data) where the column "Unique" matches in both T1 and T2 but I can't quit get my syntax down. I am using the Update command but is there an easy way of writing it where I don't have to set all of the columns (there are bout 20) from T1 = T2 Thanks for all the help!Sean |
|
|
maevr
Posting Yak Master
169 Posts |
Posted - 2010-12-20 : 01:05:41
|
| update a set a.col1 = b.col1 ,a.col2 = b.col2from tbl1 a inner join tbl2 bon a.id = b.id |
 |
|
|
sogorman
Starting Member
5 Posts |
Posted - 2010-12-20 : 08:19:18
|
| MaevrThanks for helping me out, I appreciate it! Can you take a look at my query below? I keep getting the error below. Thanks again all for lending me some of your knowledge!Error: Server: Msg 107, Level 16, State 3, Line 6The column prefix 'PlayTableHolding' does not match with a table name or alias name used in the query.Query:SELECT * INTO PlayTableHolding FROM PlayTable WHERE ID like '%HD_%'Update PlayTableHoldingSET HasOffset = 1update PlayTable setPlayTable.Number = PlayTableHolding.Number,PlayTable."Unique" = PlayTableHolding."Unique",PlayTable."ID" = PlayTableHolding."ID",PlayTable.Title = PlayTableHolding.Title,PlayTable.ScheduledTime = PlayTableHolding.ScheduledTime,PlayTable.ActualTime = PlayTableHolding.ActualTime,PlayTable.Status = PlayTableHolding.Status,PlayTable.EventType = PlayTableHolding.EventType,PlayTable.Source = PlayTableHolding.Source,PlayTable.SwitchDuration = PlayTableHolding.SwitchDuration,PlayTable.Transistion = PlayTableHolding.Transistion ,PlayTable.TransistionDuration = PlayTableHolding.TransistionDuration,PlayTable.TrigType = PlayTableHolding.TrigType,PlayTable.TrackUnique = PlayTableHolding.TrackUnique,PlayTable.HasOffset = PlayTableHolding.HasOffset,PlayTable."Play Duration" = PlayTableHolding."Play Duration",PlayTable.OffsetTrack = PlayTableHolding.OffsetTrack,PlayTable.AirDate = PlayTableHolding.AirDate,PlayTable.OverrideDuration = PlayTableHolding.OverrideDuration,PlayTable.TapeLoaded = PlayTableHolding.TapeLoaded,PlayTable.TrafficDuration = PlayTableHolding.TrafficDuration,PlayTable.TrafficHitTime = PlayTableHolding.TrafficHitTimefrom PlayTable a inner join PlayTableHolding bon PlayTable."Unique" = PlayTableHolding."unique" |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-12-20 : 08:24:42
|
You have aliased PlayTableHolding as "b" by using:join PlayTableHolding b so everywhere you have referenced "PlayTableHolding." needs to therefore be changed to "b." |
 |
|
|
sogorman
Starting Member
5 Posts |
Posted - 2010-12-20 : 08:58:41
|
| Thanks Kristin! Works like a charm!I'll sure I'll be back with more questions :) |
 |
|
|
sogorman
Starting Member
5 Posts |
Posted - 2010-12-20 : 09:37:25
|
| Ok hopefully last question....I have added some lines to my query in where i am attempting to inset data into a table and I am getting the error...Server: Msg 8101, Level 16, State 1, Line 60An explicit value for the identity column in table 'PlayTableOffset' can only be specified when a column list is used and IDENTITY_INSERT is ON.Here is my query....INSERT INTO PlayTableOffsetHolding (OffsetTrack) SELECT PlayTableHolding.OffsetTrack FROM PlayTableHoldingUpdate PlayTableOffsetHolding SET Offset='+00:00:10:00', AutoInc ='9999999', "Action" = 'RunMacro', "Device" = 'Macro', "Option1" = 'Test'INSERT INTO PlayTableOffset SELECT * FROM PlayTableOffsetHoldingShould I add the lineSET IDENTITY_INSERT PlayTableOffset ONafter my Insert INSERT INTO PlayTableOffset SELECT * FROM PlayTableOffsetHoldingThanks! |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-12-20 : 12:30:35
|
| SET IDENTITY_INSERT PlayTableOffset ONINSERT INTO PlayTableOffset SELECT * FROM PlayTableOffsetHoldingSET IDENTITY_INSERT PlayTableOffset OFF |
 |
|
|
|
|
|
|
|