Solved

trigger/store procedure

Posted on 2012-04-06
4
407 Views
Last Modified: 2012-06-21
we have a table, that every time a specific use queries it/retrieve data, we want the current record to be send to be last.

For this, we can create a "counter" field that will do this.

What would be the best approach to do this, should we use SQL from the server side asp file, a trigger or a stored procedure ?

In SQL would be something like:

SELECT USERNAME, DESCRIPTION, RECORDID, COUNTER FROM TABLE1 ORDER BY COUNTER

then...

UPDATE TABLE1 SET description = description.Text()  Where username = SUserName.Text()
and recordid = recordid.Text()

then

Rs.Movelast;  (classic asp)

sCOUNTER  = Rs.("Counter") +1;

UPDATE TABLE1 SET Counter =  wCOUNTER
0
Comment
Question by:goodluck11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Assisted Solution

by:micropc1
micropc1 earned 250 total points
ID: 37818247
Its possible i'm misunderstanding what you're asking, but I think you're just wanting the last updated record to be at the top. Why not add a datetime field and set it to the current date in your update statement?

UPDATE TABLE1
SET description = description.Text(),
lastModified = CURRENT_TIMESTAMP
Where username = SUserName.Text()
and recordid = recordid.Text()

...then when you select, order by lastModified DESC
0
 
LVL 9

Accepted Solution

by:
keyu earned 250 total points
ID: 37822496
1)  Do you mean you want to display latest inserted record last  ?
     if so

create trigger on insert

UPDATE TABLE1
SET lastModified = now()
Where username = SUserName.Text()
and recordid = recordid.Text()


2)   if you want last access records by using selection or updation query

create trigger on select,Update

UPDATE TABLE1
SET lastModified = now()
Where username = SUserName.Text()
and recordid = recordid.Text()

=============================================================================

                    ==> if you want last updated record last :->

                          SELECT USERNAME, DESCRIPTION, RECORDID, COUNTER FROM TABLE1 ORDER BY LASTMODIFIED

                    ==> if you want last updated record first:->

                           SELECT USERNAME, DESCRIPTION, RECORDID, COUNTER FROM TABLE1 ORDER BY LASTMODIFIED DESC
0
 

Author Comment

by:goodluck11
ID: 37826165
THANKS FOR YOUR REPLY

> wanting the last updated record to be at the top

Would be the last record accessed ,, to go to last,,,
0
 
LVL 9

Expert Comment

by:keyu
ID: 37831918
ok than my above post will work for you just create trigger and write the query
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question