Microsoft SQL query for logged in users (example 1):

SELECT LOCKCONNECTIONS.USER_ID, USERS.NAME
FROM LOCKCONNECTIONS
INNER JOIN USERS ON LOCKCONNECTIONS.USER_ID = USERS.USER_ID



Microsoft SQL query for logged in users (example 2):


SELECT spid, loginame, hostname, net_library, program_name, dbid ,login_time,last_batch As Last_Activity
FROM master.dbo.sysprocesses
WHERE
(master.dbo.sysprocesses.dbid = (SELECT dbid FROM master.dbo.sysprocesses WHERE spid = @@SPID ))
AND (master.dbo.sysprocesses.spid > 50)
AND (RIGHT(rtrim(master.dbo.sysprocesses.program_name),17) <> '_ReportConnection')
AND (master.dbo.sysprocesses.spid <> @@SPID)


Microsoft SQL query for past user activity on the database:

SELECT spid, loginame, hostname, net_library, program_name, dbid ,login_time,last_batch As Last_Activity
FROM master.dbo.sysprocesses
WHERE
(master.dbo.sysprocesses.dbid = (SELECT dbid FROM master.dbo.sysprocesses WHERE spid = @@SPID ))


Microsoft Access query for logged in users:

SELECT
DBO_LOCKCONNECTIONS.USER_ID, DBO_USERS.NAME
FROM
DBO_LOCKCONNECTIONS INNER JOIN DBO_USERS ON
DBO_LOCKCONNECTIONS.USER_ID = DBO_USERS.USER_ID;


Disclaimer: Blackbaud provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Structured Query Language and the tools used to create and modify SQL statements and Crystal Reports. Blackbaud Customer Support may help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality.