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 |
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2009-03-05 : 11:12:09
|
| How to update data from temp table to real table.I tried this but get error:Msg 4104, Level 16, State 1, Line 1The multi-part identifier "#temp.ID" could not be bound.Create table tbl1 (ID INT,email varchar(255),domain_name varchar(50),email_name varchar(50))goINSERT INTO tbl1SELECT 1, 'Aa Bb <abb@xyz.com>; Pr, Eda <peda@abc.com>; R Man <rman@xyz.com>; Kim Park <kpark@mmm.com',NULL,NULLINSERT INTO tbl1SELECT 2, 'Ra, Ja <rja@cc.com>; Rr Gg <rgg@cc.com>',NULL,NULLINSERT INTO tbl1SELECT 3, '<nimnn@mmm.com>; <myjob@mycompany.com>',NULL,NULLgoCreate table #temp (ID INT,domain_name varchar(50),email_name varchar(50))goINSERT INTO #tempSELECT 1, 'xyz.com;abc.com;mm.com','Aa Bb;Pr;Eda;R Man; Kim Park'INSERT INTO #tempSELECT 2, 'cc.com','Ra;Ja;Rr Gg'INSERT INTO #tempSELECT 3, 'mmm.com',NULLgoUpdate Mydb.dbo.tbl1 SET domain_name=#temp.domain_name, email_name=#temp.email_name WHERE ID=#temp.IDgoDrop table tbl1Drop table #temp |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-03-05 : 11:39:10
|
| You were missing a FROM clause. I also added a table prefix to tbl1 in your WHERE clause because the ID column was ambiguous:UPDATE tbl1SET domain_name=#temp.domain_name, email_name=#temp.email_name FROM tbl1, #tempWHERE tbl1.ID=#temp.IDSome days you're the dog, and some days you're the fire hydrant. |
 |
|
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2009-03-05 : 11:43:18
|
| thankx perfect job |
 |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-03-05 : 11:51:11
|
| No problem :)Some days you're the dog, and some days you're the fire hydrant. |
 |
|
|
|
|
|
|
|