Topic Last Modified: 2012-10-06

This section contains sample queries for the Persistent Chat database.

Use the following example to get a list of your most active Persistent Chat rooms after a certain date.

Copy Code
SELECT nodeName as ChatRoom, COUNT(*) as ChatMessages
  FROM tblChat, tblNode
  WHERE channelId = nodeID AND dbo.fnTicksToDate(chatDate) > '1/1/2011'
  GROUP BY nodeName
  ORDER BY ChatMessages DESC

Use the following example to get a list of your most active users after a certain date.

Copy Code
SELECT prinName as Name, count(*) as ChatMessages
  FROM tblChat, tblPrincipal
  WHERE prinID = userId AND dbo.fnTicksToDate(chatDate) > '1/1/2011'
  GROUP BY prinName
  ORDER BY ChatMessages DESC

Use the following example to get a list of everyone who ever sent a message with "Hello World" in it.

Copy Code
SELECT nodeName as ChatRoom, prinName as Name, content as Message
  FROM tblChat, tblNode, tblPrincipal
  WHERE channelId = nodeID AND userId = prinID AND content like '%Hello World%'

Use the following example to get a list of group memberships for a certain principal.

Copy Code
SELECT prinName as Name
  FROM tblPrincipalAffiliations as pa, tblPrincipal
  where principalID = 7 and affiliationID = prinID

Use the following example to get a list of every chat room that a user, Jane Dow, is a direct member of.

Copy Code
SELECT DISTINCT nodeName as ChatRoom, prinName as Name	
  FROM tblPrincipalRole, tblPrincipal, tblNode
  WHERE  prinRoleNodeID = nodeID AND prinRolePrinID = prinID AND prinName = 'Jane Dow'

Use the following example to get a list of invitations that a user has received.

Copy Code
SELECT prinName
	,nodeName
	,invID   
	,createdOn
  FROM tblPrincipalInvites as inv, tblPrincipal as p, tblNode as n
  where inv.prinID = 5 AND inv.prinID = p.prinID and inv.nodeID = n.nodeID
  ORDER BY invID DESC