2017-06-19 32 views
2
LogID Title Message 
1 Error Occured Could not find stored procedure 'RT_SELECTAll1_Users'. : [UserID={2}],[UserSessionID={10068}] 
2 Error Occured A public action method 'LogsIndex' was not found on controller 'oMail.Web.Controllers.EmailTemplateController'. : [UserID={2}],[UserSessionID={20071}] 
3 Error Occured The controller for path '/ControllerName/ActionName' was not found or does not implement IController. : [UserID={2}],[UserSessionID={20071}] 
4 Error Occured The controller for path '/ControllerName/ActionName' was not found or does not implement IController. : [UserID={2}],[UserSessionID={20071}] 
5 Error Occured The controller for path '/ControllerName/ActionName' was not found or does not implement IController. : [UserID={2}],[UserSessionID={20071}] 
6 Error Occured The controller for path '/ControllerName/ActionName' was not found or does not implement IController. : [UserID={2}],[UserSessionID={20071}] 
7 Error Occured The controller for path '/ControllerName/ActionName' was not found or does not implement IController. : [UserID={2}],[UserSessionID={20071}] 
8 Error Occured The controller for path '/ControllerName/ActionName' was not found or does not implement IController. : [UserID={2}],[UserSessionID={20071}] 

這是存儲錯誤消息的表。在SQL Server中按字符串排序列?

是否有可能獲得所有錯誤信息的計數。

例如,

消息:「LogsIndex」不是。計數= 1

消息: - '路徑控制器'不是。計數= 5

+0

SELECT Message,count(1)as MCount FROM TableName –

回答

1

因爲消息是不完全一樣的,你使用像我只能看到和案例:

SELECT 
    CASE 
     WHEN Message like '%LogsIndex%' THEN 'LogsIndex' 
     WHEN Message like 'The controller for path'' was not%' THEN 'Controller Path' 
     ELSE 'Other' 
    END AS UserMessage 
    ,count(*) 
FROM 
    TableName 
Group by 
    CASE 
     WHEN Message like '%LogsIndex%' THEN 'LogsIndex' 
     WHEN Message like 'The controller for path' was not%' THEN 'Controller Path' 
     ELSE 'Other' 
    END 

如果你想簡單地使用CTE或UNION,你可以使它更優雅。

你想限制這個日期或某事。

0

請試試這個答案。

SELECT Message, count(1) as MCount 
FROM TableName 
1

您選擇的消息,並進行計數,然後組由消息,像這樣的結果:

Select Message, Count(*) as 'Count' 
    From Table 
    Group by Message