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 2008 Forums
 Transact-SQL (2008)
 SELECT records in table from UPDATE

Author  Topic 

ckjames
Starting Member

2 Posts

Posted - 2012-11-21 : 13:40:33
I am looking to generate a table off of updated records.

Example:

3 people are about to run a race. Get that data

SELECT person_id
FROM person
WHERE date_complete IS NULL


3 people finish the race today.

UPDATE person SET date_complete = today() and last_update = now()
WHERE date_complete IS NULL


I am running this within a stored procedure and I am able to update and get the records on the fly. However, this is my problem: but the temporary table exists only for the duration of the stored procedure that creates it.

So basically I was wondering what would be the best way to populate a table with these records that were updated. I would need to see the records when this update is run and then possibly 5-10 minutes down the line. Thanks!

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-11-21 : 13:50:18
Can't you just populate a permanent table on the database instead of a temp table?

Jim

P.S. This is a MS SQL Server Forum so you may need to get advice elsewhere.

Everyday I learn something that somebody else already knew
Go to Top of Page

ckjames
Starting Member

2 Posts

Posted - 2012-11-21 : 13:53:42
quote:
Originally posted by jimf

Can't you just populate a permanent table on the database instead of a temp table?

Jim

P.S. This is a MS SQL Server Forum so you may need to get advice elsewhere.

Everyday I learn something that somebody else already knew


I thought about creating a permanent table but didn't know if I wanted the extra table floating around just for this one program. Is it bad practice to create a table then drop/delete table every time this would be run?

Basically these updated records will only need to be known/populated for about 10 minutes after this is run.
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-11-21 : 14:05:28
It's still a table that is getting used regularly and read from different sources, so I'd just create it permanently and then add
TRUNCATE TABLE myTable
INSERT INTO myTable ...


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -