Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Ektron Metrics – User Count By User Group

Posted on May 6, 2013October 26, 2015 By David Kittell

Part of the Ektron Metrics Script, this query will help with metrics to give you an idea of how often your users login.

SET NOCOUNT ON

DECLARE @month INT
	,@year INT
	,@start_date DATETIME
	,@end_date DATETIME

SET @month = (
		SELECT CASE
				WHEN MONTH(GETDATE()) = '1'
					THEN '12'
				ELSE MONTH(GETDATE()) - 1
				END
		)
--SELECT @month AS Month_To_Report
SET @year = (
		SELECT CASE
				WHEN MONTH(GETDATE()) = '1'
					THEN YEAR(GETDATE()) - 1
				ELSE YEAR(GETDATE())
				END
		)
--SELECT @YEAR AS Year_To_Report
SET @start_date = CAST(CAST(@month AS VARCHAR) + '/01/' + CAST(@year AS VARCHAR) AS DATETIME)
-- @start_date AS Start_Date
SET @end_date = (
		SELECT DATEADD(s, - 1, DATEADD(mm, DATEDIFF(m, 0, @start_date) + 1, 0))
		)

--SELECT @end_date AS End_Date
--SELECT (CONVERT(VARCHAR(8), @start_date, 1) + ' - ' + CONVERT(VARCHAR(8), @end_date, 1)) AS 'Date Range'
SELECT DISTINCT ug.usergroup_name AS "Ektron User Group"
	,(
		SELECT COUNT(*)
		FROM user_to_group_tbl utgt1
		INNER JOIN usergroups ON utgt.usergroup_id = usergroups.usergroup_id
		INNER JOIN users u ON u.user_id = utgt1.user_id
		WHERE utgt.usergroup_id = utgt1.usergroup_id
			AND (
				u.date_created <= @end_date
				OR u.date_created IS NULL
				)
		) AS "Total Users"
	,(
		SELECT COUNT(*)
		FROM user_to_group_tbl utgt1
		INNER JOIN usergroups ON utgt.usergroup_id = usergroups.usergroup_id
		INNER JOIN users u ON u.user_id = utgt1.user_id
		WHERE utgt.usergroup_id = utgt1.usergroup_id
			AND (
				u.date_created <= @end_date
				OR u.date_created IS NULL
				)
			AND u.[user_deleted] = 0
		) AS "Account Status - Active"
	,(
		SELECT COUNT(*)
		FROM user_to_group_tbl utgt1
		INNER JOIN usergroups ON utgt.usergroup_id = usergroups.usergroup_id
		INNER JOIN users u ON u.user_id = utgt1.user_id
		WHERE utgt.usergroup_id = utgt1.usergroup_id
			AND (
				u.date_created >= @start_date
				OR u.date_created IS NULL
				)
			AND (
				u.date_created <= @end_date
				OR u.date_created IS NULL
				)
			AND u.[user_deleted] = 0
		) AS "Registered Witin The Month"
	,(
		SELECT COUNT(*)
		FROM user_to_group_tbl utgt1
		INNER JOIN usergroups ON utgt.usergroup_id = usergroups.usergroup_id
		INNER JOIN users u ON u.user_id = utgt1.user_id
		WHERE utgt.usergroup_id = utgt1.usergroup_id
			AND (
				u.date_created <= @end_date
				OR u.date_created IS NULL
				)
			AND u.[user_deleted] = 0
			AND convert(VARCHAR, LAST_LOGIN_DATE, 112) <= GETDATE() - 120
		) AS "Login Status - <= 120"
	,(
		SELECT COUNT(*)
		FROM user_to_group_tbl utgt1
		INNER JOIN usergroups ON utgt.usergroup_id = usergroups.usergroup_id
		INNER JOIN users u ON u.user_id = utgt1.user_id
		WHERE utgt.usergroup_id = utgt1.usergroup_id
			AND (
				u.date_created <= @end_date
				OR u.date_created IS NULL
				)
			AND u.[user_deleted] = 0
			AND convert(VARCHAR, LAST_LOGIN_DATE, 112) <= GETDATE() - 90
		) AS "Login Status - <= 90"
	,(
		SELECT COUNT(*)
		FROM user_to_group_tbl utgt1
		INNER JOIN usergroups ON utgt.usergroup_id = usergroups.usergroup_id
		INNER JOIN users u ON u.user_id = utgt1.user_id
		WHERE utgt.usergroup_id = utgt1.usergroup_id
			AND (
				u.date_created <= @end_date
				OR u.date_created IS NULL
				)
			AND u.[user_deleted] = 0
			AND convert(VARCHAR, LAST_LOGIN_DATE, 112) <= GETDATE() - 30
		) AS "Login Status - <= 30"
FROM user_to_group_tbl utgt
INNER JOIN usergroups ug ON utgt.usergroup_id = ug.usergroup_id
ORDER BY "Ektron User Group"
Originally Posted on May 6, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code Ektron Ektron User Management MSSQL MSSQL - Ektron MSSQL - Ektron 8.0.2 MSSQL - Ektron 8.7 SQL

Post navigation

Previous post
Next post

Related Posts

Provider Detail With Address

Posted on September 16, 2013October 26, 2015

SELECT firstname ,lastname ,prov_nbr ,npi ,address1 ,city ,STATE ,zip FROM provider ,address WHERE addr_who = ‘P ‘ || prov_nbr AND ymdeff <= to_char(sysdate, ‘yyyymmdd’) AND ymdend >= to_char(sysdate, ‘yyyymmdd’) AND void <> ‘Y’ AND substr(addrtype_who, 1, 1) = ‘D’ AND prov_nbr = ‘<Provider Number>’; Originally Posted on September 16, 2013Last…

Read More

WordPress – Ninja Forms – Disable Form Saves

Posted on December 18, 2015December 21, 2015

If you have a concern about PHI or other concerns of saving data on your SQL database of the Ninja Forms follow the step on their site http://docs.ninjaforms.com/customer/en/portal/articles/2045697-faq#faq_save on the save-sub.php file. The save-sub.php location may vary based on your operating system but if you are on a UNIX based…

Read More

Calculate BMI

Posted on April 16, 2014October 26, 2015

static int CalculateBMI(int weight, int height) { return (weight * 703) / (height * height); } Originally Posted on April 16, 2014Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or program is ran on a production…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes