asked on
SELECT 'UserA', SUM(CASE WHEN CHARINDEX('UserA',ISNULL(User1,'') + ISNULL(User2,'') + ISNULL(User3,''),0) <> 0 THEN 1 ELSE 0 END) UserCount
FROM Table1
UNION ALL
SELECT 'UserB', SUM(CASE WHEN CHARINDEX('UserB',ISNULL(User1,'') + ISNULL(User2,'') + ISNULL(User3,''),0) <> 0 THEN 1 ELSE 0 END) UserCount
FROM Table1
UNION ALL
SELECT 'UserC', SUM(CASE WHEN CHARINDEX('UserC',ISNULL(User1,'') + ISNULL(User2,'') + ISNULL(User3,''),0) <> 0 THEN 1 ELSE 0 END) UserCount
FROM Table1
ASKER
ASKER
ASKER
Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.
TRUSTED BY
1) Create one Temporary Table with 3 Columns
ID
UserName
Count
2) Fire a GroupBy Query on User1 Column with selection Count (in your main table)
and then add this data to you temprary table
3) and 4) do the same for Column2 and Column3
Then refer your temprary table for final summary