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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 UPDATE table from another table

Author  Topic 

MaverickUK
Yak Posting Veteran

89 Posts

Posted - 2005-02-14 : 11:08:22
Howdy folks

I'm having difficulties extracting the data I need from MS SQL Server, and hope that some bright spark can help me out.

I have a memory based temp table


DECLARE
@TT_CurrentVisitors TABLE
(
UID INT IDENTITY(1,1),
VisitorID INT,
LastLog DATETIME,
PageID INT,
PageTitle VARCHAR(150)
)


I then fill insert a number of rows filling the VisitorID and LastLog fields.

I then need to update the temp table against another data source, something like


UPDATE @TT_CurrentVisitors AS TT_CV
SET
TT_CV.PageID = SELECT PageID FROM Pages WHERE VisitorID = TT_CV.VisitorID


Is this possible to do? Please help!

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-14 : 11:11:56
will this do?

UPDATE t1
SET PageID = t2.PageID
from @TT_CurrentVisitors t1
inner join Pages t2 on t2.VisitorID = t1.VisitorID

Go with the flow & have fun! Else fight the flow
Go to Top of Page

MaverickUK
Yak Posting Veteran

89 Posts

Posted - 2005-02-14 : 12:08:36
I think it may well!

After all these years, I *still* have difficulties thinking in database terms as opposed to tradtional programming logic!

Thanks
Go to Top of Page
   

- Advertisement -