Solved

trigger/store procedure

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help writing a query 6 71
Error on Add method 1 37
Entity Framework 7 28
Access 2010 Query Syntax 5 18
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 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

20 Experts available now in Live!

Get 1:1 Help Now