Solved

trigger/store procedure

Posted on 2012-04-06
4
406 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

Independent Software Vendors: 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

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

751 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