tcmmaxt
asked on
how do you flag a sql 2005 server database record where there has been no action for 8 hours
I need to develop an sql query to select a record (from ATable below) where there has been no action for 8 hours. Each record in ATable includes a field called requestDate(type datetime) and a field named statusname (varchar). When requestDate = requestDate + 8 hours and the statusname field reads “pending”.
I would like to update (set) the “sendemail” field to read “yes” Please update the sql code below to do this task. The query will be run by other means and not part of this task.
thank you
Select xyzID,
requestDate,
statusname,
sendemail,
From ATable
Update .......
I would like to update (set) the “sendemail” field to read “yes” Please update the sql code below to do this task. The query will be run by other means and not part of this task.
thank you
Select xyzID,
requestDate,
statusname,
sendemail,
From ATable
Update .......
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@PatelAlpesh:
My reading of the question is that requestDate is the updatedate field and Asker is looking for the select/update query to use to track the record based on the current datetime.
My reading of the question is that requestDate is the updatedate field and Asker is looking for the select/update query to use to track the record based on the current datetime.
ASKER
thanks mwvisa1 (and all): the idea here is the requestDate field logs the time when the user makes a request for something. After 8 hours if the data in the statusname field does not read "pending" . I would like to update (set) the “sendemail” field to read “yes” which somehow will fire off an email alerting others that 8 hours have elapsed and no one has responsed to the request. Of course I need to figure how to capture and reset “sendemail” field to read "no".
I need the first 2 scripts since i have to update eact time and somehow reset the fields after email fire off?
Select xyzID,
requestDate,
statusname,
sendemail
From ATable
Where requestDate <= DateAdd(hh, -8, GetDate())
Update ATable
Set sendemail = 'Yes'
Where requestDate <= DateAdd(hh, -8, GetDate())
I need the first 2 scripts since i have to update eact time and somehow reset the fields after email fire off?
Select xyzID,
requestDate,
statusname,
sendemail
From ATable
Where requestDate <= DateAdd(hh, -8, GetDate())
Update ATable
Set sendemail = 'Yes'
Where requestDate <= DateAdd(hh, -8, GetDate())
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is so, I would do something like this:
Open in new window
If you need this to do an update, then you would just do this:
Open in new window
Or without actually updating the table, you could do this in the query:
Open in new window
Hope that helps!