Click here to Skip to main content
15,917,062 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i want to save select output to use it

example:

table1:

userid|date|
____________
1 |27/3/2010
2 |27/1/2010
1 |28/2/2011
2 |6/4/2011
_______________


table2:
statues|userid
_______________
active |1
active |2
_____________


i get last inserted date from table1 and compare to datenow

"select  DISTINCT userid,MAX(date)as date from table1 group by userid"


how to get result and
update table2 where table2.userid=???????


what is the where condition????
Posted
Updated 2-Apr-11 5:15am
v2
Comments
milenalukic 2-Apr-11 11:27am    
What is your problem? explain better so that users can help you.

1 solution

You didn't specify the logic very much so if I understood correctly, your update could be something like:
SQL
UPDATE Table2
SET Status = 'Active'
WHERE Table2.UserId IN (SELECT DISTINCT userid
                        from table1 
                        WHERE date > DATEADD( day, -5, GETDATE()))
AND Table2.Status <> 'Active'
The above should update the status to active if the date in date column is greater than five days ago.

However if the status is dependent on nondeterministic value (such as current date, which constantly changes), I wouldn't advice to store the status, just to query the status when it's needed.
 
Share this answer
 
Comments
Monjurul Habib 2-Apr-11 11:48am    
good call.5+
Wendelius 2-Apr-11 12:01pm    
Thank you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900