Skip to the main content.

1 min read

OCS 2007 Archiving SQL Queries

These are copied from the ArchivingCDRReporter read me…The following are some user specific SQL query samples that are intended to guide you through extracting relevant reporting user or time range specific information from the Archiving/CDR Database. The general usage queries are already added as part of the tool.

1. Find IMs containing specific word.

SELECT * FROM DatabaseName.Dbo.messages where body like N’%your-search-word%’

2. Find all IMs sent by a user.

SELECT * from DatabaseName.Dbo.messages, DatabaseName.Dbo.users where DatabaseName.Dbo.users.userid = messages.fromid and DatabaseName.Dbo.users.useruri = ‘user-you-are-looking-for’

3. Find all IMs received by a user.

SELECT * from DatabaseName.Dbo.messages, DatabaseName.Dbo.users where DatabaseName.Dbo.users.userid = DatabaseName.Dbo.messages.toid and DatabaseName.Dbo.users.useruri = ‘user-you-are-looking-for’

4. Find IM body, sender and receiver information from all IMs exchanged between two users

SELECT body, u1.useruri as [from], u2.useruri as [to] from DatabaseName.Dbo.messages, DatabaseName.Dbo.users u1, DatabaseName.Dbo.users u2 where DatabaseName.Dbo.messages.fromid = u1.userid and DatabaseName.Dbo.messages.toid = u2.userid and u1.useruri = ‘first-user’ and u2.useruri = ‘second user’

UNION ALL

SELECT body, u1.useruri , u2.useruri from DatabaseName.Dbo.messages, DatabaseName.Dbo.users u1, DatabaseName.Dbo.users u2 where DatabaseName.Dbo.messages.fromid = u2.userid and DatabaseName.Dbo.messages.toid = u1.userid and u2.useruri = ‘first-user’ and u1.useruri = ‘second user’

5. Find all IMs sent between certain time range

SELECT * from DatabaseName.Dbo.messages where date (greater than symbol) ‘Start time’ and date (less than symbol) ‘end time’

6. Find all IMs sent by a user within time range

SELECT * from DatabaseName.Dbo.messages, DatabaseName.Dbo.users where DatabaseName.Dbo.users.userid = DatabaseName.Dbo.messages.fromid and DatabaseName.Dbo.users.useruri = ‘user-you-are-looking-for’ and date (greater than symbol) ‘Start time’ and date (less than symbol) ‘end time’

7. General usage report data

SELECT r.dialogid as “Dialog ID”, u1.useruri as “From user”, u2.useruri as “To user”, media.starttime as “Start Time”, datediff(mi,starttime, endtime) as “Time in minutes”, medialist.media as “Session type”

from users u1

inner join requestresponsecount r on r.fromid = u1.userid

inner join users u2 on r.toid = u2.userid

inner join media on media.dialogid = r.dialogid

inner join medialist on medialist.id = media.mediaid

Note: Change mi to s if you want the length of session in seconds

Decoding the Azure Stack: Global Azure, Azure Stack Hub, and Azure Stack HCI

Decoding the Azure Stack: Global Azure, Azure Stack Hub, and Azure Stack HCI

As organizations pivot towards a hybrid cloud strategy, understanding the nuances between Global Azure, Azure Stack Hub, and Azure Stack HCI becomes...

Understanding Extended Security Update Options for Windows Server 2012

Understanding Extended Security Update Options for Windows Server 2012

Windows Server 2012/R2, a cornerstone of server operating systems, reached its end-of-life on October 10, 2023. This cessation of regular...

Navigating the Upcoming Changes to the Azure RI Exchange Policy

Navigating the Upcoming Changes to the Azure RI Exchange Policy

As cloud infrastructure becomes central to business operations, it's essential to understand the nuances of cloud resource management for...