Solved

Need to group the result

Posted on 2012-04-12
2
415 Views
Last Modified: 2012-06-27
There are 2 tables one contains present details and other once contains older details.I need to group into one common title.

Right Now i am getting result like

MSSQLSERVER.Application.pgTIPSR.17063General.Alert      2
MSSQLSERVER.Application.pgTIPSR.Error50000Severity16State1.Alert      2
MSSQLServer.Application.SQLServer.Themirroringconnectionhastimedout.Alert      3--
MSSQLServer.Application.SQLServer.Themirroringconnectionhastimedout.Alert      4-- need to be combined 3&4 to one as title are same
MSSQLSERVER.TMFSQL.MSSQLSERVER.Alert      15
SQLServerAgent.Application.SQLServer.SQLServerAgent208.Alert      5
StorageAgents.Hardware.StorageAgentsSYSTEM.Alert      1
StorageAgents.Hardware.StorageAgentsSYSTEMWARNING.Alert      1


My expected out is

MSSQLSERVER.Application.pgTIPSR.17063General.Alert      2
MSSQLSERVER.Application.pgTIPSR.Error50000Severity16State1.Alert      2
MSSQLServer.Application.SQLServer.Themirroringconnectionhastimedout.Alert      7 ------------------ It's should have 2 entries for same title.It's needs to grouped.
MSSQLSERVER.TMFSQL.MSSQLSERVER.Alert      15
SQLServerAgent.Application.SQLServer.SQLServerAgent208.Alert      5
StorageAgents.Hardware.StorageAgentsSYSTEM.Alert      1
StorageAgents.Hardware.StorageAgentsSYSTEMWARNING.Alert      1


Query:

SELECT SUBSTRING (SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc)),
      CHARINDEX('.', SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc))) + 1, 1000),
      COUNT (*)
FROM CT
WHERE pid =111 and  ticketdesc like '%sql%' and createddtim >='2012-03-11' and PATINDEX ('%Event[0-9]%', ticketdesc) > 0
And CHARINDEX (';  Desc:', ticketdesc) > 0
Group by SUBSTRING (SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc)),
      CHARINDEX('.', SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc))) + 1, 1000)
     
      union
      SELECT SUBSTRING (SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc)),
      CHARINDEX('.', SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc))) + 1, 1000),
      COUNT (*)
FROM T
WHERE pid =111 and  ticketdesc like '%sql%' and createddtim >='2012-03-11' and PATINDEX ('%Event[0-9]%', ticketdesc) > 0
And CHARINDEX (';  Desc:', ticketdesc) > 0
Group by SUBSTRING (SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc)),
      CHARINDEX('.', SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc))) + 1, 1000)
0
Comment
2 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 37840588
try

select group_name, sum(cnt) from (
SELECT SUBSTRING (SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc)),
      CHARINDEX('.', SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc))) + 1, 1000) group_name,
      COUNT (*) cnt
FROM CT
WHERE pid =111 and  ticketdesc like '%sql%' and createddtim >='2012-03-11' and PATINDEX ('%Event[0-9]%', ticketdesc) > 0
And CHARINDEX (';  Desc:', ticketdesc) > 0
Group by SUBSTRING (SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc)),
      CHARINDEX('.', SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc))) + 1, 1000)
     
      union
      SELECT SUBSTRING (SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc)),
      CHARINDEX('.', SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc))) + 1, 1000),
      COUNT (*)
FROM T
WHERE pid =111 and  ticketdesc like '%sql%' and createddtim >='2012-03-11' and PATINDEX ('%Event[0-9]%', ticketdesc) > 0
And CHARINDEX (';  Desc:', ticketdesc) > 0
Group by SUBSTRING (SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc)),
      CHARINDEX('.', SUBSTRING (ticketdesc, PATINDEX ('%Event[0-9]%', ticketdesc), CHARINDEX (';  Desc:', ticketdesc) - PATINDEX ('%Event[0-9]%', ticketdesc))) + 1, 1000)
) t
group by group_name
0
 
LVL 5

Author Closing Comment

by:VIVEKANANDHAN_PERIASAMY
ID: 37840703
Awesome
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question