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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Updating a table from a temp table

Author  Topic 

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2007-06-06 : 07:24:56
Hello all.

I have a temp table called #JOB which i know contains data (i can select from it and it shows about 30 rows). The problem is when i am trying to update another table with the contents of the temp table...........query analyser tells me no rows have been updated.

here is the code i am using:

UPDATE JOB	
SET JOB.JOB_REF = #JOB.JOB_REF
FROM #JOB


Does anyone have any ideas where i am going wrong? Cheers in advance.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-06 : 07:27:08
[code]Update j
Set Job_Ref = t.Job_ref
From Job j Join #Job t on j.id = t.id[/code]

Note: I am assuming ID as Primary Key column here (common joining field).

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2007-06-06 : 07:27:58
Are you trying to insert these records? If you're updating a table, it has to be present in the FROM clause of the statement. This would require you to join JOB to #JOB. However, since you're updating the joining key, this would be problematic!

Mark
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-06 : 07:28:05
[code]
UPDATE J
SET JOB_REF = T.JOB_REF
FROM JOB J INNER JOIN #JOB T
ON J.somecol = T.somecol
[/code]


KH

Go to Top of Page

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-06-06 : 07:28:49
U have to use like

Update j
Set j.JOB_REF = tj.JOB_REF
From JOB j join #job tj
on <your condition>

--------------------------------------------------
S.Ahamed
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-09 : 07:00:45
Too many Snipes

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -