I am in a hurry. How can I write such an SQL statement?

Source: Internet
Author: User
I am in a hurry. How can I write such an SQL statement? Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061216082939279.html
There are two tables,
Table1: loginoutinfo-records the time when the system administrator enters or exits. Of course, use "End Task"
Method is disabled Program It cannot be recorded, and there will be only login, but no logout.
Loginoutinfo (user (char (20), logtime (datetime), logstatus (char (10 )))
The record is as follows:
Admin 2006-12-15 10:25:36 Login
Admin 2006-12-15 10:55:36 logout
Admin 2006-12-15 10:59:10 login -- the task is terminated here, so there is no logout
User1 2006-12-15 11:09:20 Login
User1 11:15:11 logout
......

Table2: eventloginfo
-- Record all operations performed by the Administrator in the system
Eventloginfo (evttime (datetime), evtcontent (nvarchar (100 )))
The record is as follows:
2006-12-12 10:26:07 delete a record
10:26:12 Add a record
11:01:07 backup database
2006-12-12 11:10:54 delete a user
....

I want to get this result (in fact, I want to add the operations to the description ):
2006-12-12 10:26:07 delete a record by admin
10:26:12 Add a record by admin
2006-12-12 11:01:07 backup database by admin
2006-12-12 11:10:54 delete a user by user1
....

How can I write such a statement?
Thank you very much,

DelphiCommunityPopularity is really bad !!

Only one administrator can log on at a time.

We recommend that you add a user field to the eventloginfo table to record the login user.
Insert into eventloginfo values (... write the same SQL statement
Parambyname ('evttime'). Value: = now;
Parambyname ('evtcontent'). Value: = 'action' + 'user ';

Create Table # loginoutinfo (logno char (20), logtime datetime, logstatus char (10 ))
Insert into # loginoutinfo
Select 'admin', '2017-12-15 10:25:36 ', 'login'
Union all select 'admin', '2017-12-15 10:55:36 ', 'logout'
Union all select 'admin', '2017-12-15 10:59:10 ', 'login'
Union all select 'user1', '2017-12-15 11:09:20 ', 'login'
Union all select 'user1', '2017-12-15 11:15:11 ', 'logout'

Create Table # event (evttime datetime, evtcontent nvarchar (100 ))

Insert into # event
Select '2014-12-12 10:26:07 ', 'delete a record'
Union all select '2017-12-12 10:26:12 ', 'Add a record'
Union all select '2017-12-12 11:01:07 ', 'backup database'
Union all select '2017-12-12 11:10:54 ', 'delete a user'
Table created for everyone,

Liaosummer

I understand what you mean. Do you mean to include the operator directly when recording EventLog?
Yes,
But now the time is not allowed,
The customer is eager to get the goods, so he plans to use the statement first and then change it here !!
Thank you very much...

I don't know what the owner means. Do you want to find out the records of eventloginfo. evttime in loginoutinfo. logtime? Do you have to associate these two records ??

You noted down who logged on. When recording the action, you simply + the user name?
Set a global variable Username

Worried and detours...

No.

Select. evttime,. evtcontent, B. user From Table2 a left join Table1 B on B. logtime <. evtime order by B. logtime Desc: obtains the administrator user who logs on to the logstore at the latest time less than the current operation time.
However, it is best to add a user record in Table 2 as described by the above heroes.
Note: It is not tested with handwriting!

select top 1. evttime,. evtcontent, B. user From Table2 a left join Table1 B on B. logtime <. evtime order by B. logtime DESC
forgot top1 [SQL Server]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.