Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SELECT records in table from UPDATE
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ckjames
Starting Member

USA
2 Posts

Posted - 11/21/2012 :  13:40:33  Show Profile  Reply with Quote
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!

Edited by - ckjames on 11/21/2012 13:40:57

jimf
Flowing Fount of Yak Knowledge

USA
2875 Posts

Posted - 11/21/2012 :  13:50:18  Show Profile  Reply with Quote
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

USA
2 Posts

Posted - 11/21/2012 :  13:53:42  Show Profile  Reply with Quote
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.

Edited by - ckjames on 11/21/2012 13:56:00
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2875 Posts

Posted - 11/21/2012 :  14:05:28  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000