Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

trigger/store procedure

Posted on 2012-04-06
4
Medium Priority
?
409 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
  • 2
4 Comments
 
LVL 7

Assisted Solution

by:micropc1
micropc1 earned 1000 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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

916 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