Solved

trigger/store procedure

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
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.​
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now