Click here to Skip to main content
15,895,011 members
Home / Discussions / Database
   

Database

 
GeneralRe: Retrieve records from sqlserver 2005 which are today inserted Pin
PIEBALDconsult6-Sep-12 4:51
mvePIEBALDconsult6-Sep-12 4:51 
QuestionHow to join two sql queries together? Pin
turbosupramk35-Sep-12 11:09
turbosupramk35-Sep-12 11:09 
AnswerRe: How to join two sql queries together? Pin
Mycroft Holmes5-Sep-12 12:49
professionalMycroft Holmes5-Sep-12 12:49 
AnswerRe: How to join two sql queries together? Pin
Osama Bin Laden 20125-Sep-12 15:02
Osama Bin Laden 20125-Sep-12 15:02 
AnswerRe: How to join two sql queries together? Pin
pmpdesign5-Sep-12 19:29
pmpdesign5-Sep-12 19:29 
GeneralRe: How to join two sql queries together? Pin
turbosupramk36-Sep-12 4:10
turbosupramk36-Sep-12 4:10 
AnswerRe: How to join two sql queries together? Pin
Niju16-Sep-12 6:32
Niju16-Sep-12 6:32 
GeneralRe: How to join two sql queries together? Pin
turbosupramk36-Sep-12 9:57
turbosupramk36-Sep-12 9:57 
Someone helped me come up with this code today, it appears to be producing the proper results, what does every one think?

It uses And UserName Not In, and brings in the second search to compare.



-- Mailbox size query users who are set to unlimited, distinct username field with disabled mailboxes removed from search
SELECT AED.ObjectName,
       AED.ObjectCanonical,
       AEM.EventMessage,
       AED.OrganizationalUnit                               AS DirectoryOrganizationalUnit,
       AET.UserName,
       AET.SeverityID,
       AET.TimeDetected,
       AET.ValueOld,
       AET.ValueNew,
       ECS.SubsystemID,
       ISNULL(ECS.CustomEventClassName, ECS.EventClassName) AS EventClassName,
       ISNULL(TSR.ServerName, TWP.MachineName)              AS ServerName,
       EAN.ActionName,
       ISNULL(TDN.DomainName, TWP.WorkgroupName)            AS DomainName,
       AET.ResultID,
       AET.EventID,
       ECS.ValueTypeID,
       AET.MissingOld,
       AET.MissingNew,
       AET.TimeZoneOffset
FROM   Audit.Event AS AET
       INNER JOIN [Event].Class AS ECS
         ON AET.EventClassID = ECS.EventClassID
       INNER JOIN Audit.EventMessage AS AEM
         ON AET.EventID = AEM.EventID
       INNER JOIN [Event].[Action] AS EAN
         ON AET.ActionID = EAN.ActionID
       LEFT OUTER JOIN Topology.[Server] AS TSR
         ON AET.AgentID = TSR.ServerID
       LEFT OUTER JOIN Topology.Domain AS TDN
         ON TSR.DomainID = TDN.DomainID
       LEFT OUTER JOIN Topology.Workgroup AS TWP
         ON AET.AgentID = TWP.MachineID
       LEFT OUTER JOIN Audit.EventDirectory AS AED
         ON AET.EventID = AED.EventID
WHERE  AET.TimeDetected >= '2012-06-08T04:00:00' 
       AND EXISTS(SELECT AET.EventID 
                  FROM   [Event].Class AS _EC 
                  WHERE  EXISTS(SELECT * 
                                FROM   Query.EventClass AS _ECQ 
                                WHERE  _ECQ.QueryID = '2E84F194-03D0-4218-A346-76C50B98E36A' 
                                       AND _ECQ.ProcessID = 0 
                                       AND StorageClassID = 0 
                                       AND _ECQ.EventClassID = _EC.EventClassID) 
                         AND _EC.EventClassID = AET.EventClassID) 
       AND NOT EXISTS(SELECT * 
                      FROM   (SELECT _QA.SID AS UserSID 
                              FROM   Query.[Account] AS _QA 
                              WHERE  _QA.QueryID = '2E84F194-03D0-4218-A346-76C50B98E36A' 
                                     AND _QA.ProcessID = 0) AS _SA 
                      WHERE  _SA.UserSID = AET.UserSID) 
                    
       AND ValueNew = '<Not-Set>' 
       
       AND UserName NOT IN (
       
       SELECT DISTINCT           --AED.ObjectName, 
                --AED.ObjectCanonical, 
--                  AED.OrganizationalUnit                               AS DirectoryOrganizationalUnit, 
--                  AEM.EventMessage, 
--                  AET.TimeDetected, 
--                  ECS.SubsystemID, 
                  AET.UserName--, 
--                  ISNULL(ECS.CustomEventClassName, ECS.EventClassName) AS EventClassName, 
--                  ISNULL(TSR.ServerName, TWP.MachineName)              AS ServerName, 
--                  EAN.ActionName, 
--                  ISNULL(TDN.DomainName, TWP.WorkgroupName)            AS DomainName, 
--                  AET.ResultID, 
--                  AET.EventID, 
--                  ECS.ValueTypeID, 
--                  AET.MissingOld, 
--                  AET.MissingNew, 
--                  AET.TimeZoneOffset 
FROM   Audit.Event AS AET 
       INNER JOIN [Event].Class AS ECS 
         ON AET.EventClassID = ECS.EventClassID 
       INNER JOIN Audit.EventMessage AS AEM 
         ON AET.EventID = AEM.EventID 
       INNER JOIN [Event].[Action] AS EAN 
         ON AET.ActionID = EAN.ActionID 
       LEFT OUTER JOIN Topology.[Server] AS TSR 
         ON AET.AgentID = TSR.ServerID 
       LEFT OUTER JOIN Topology.Domain AS TDN 
         ON TSR.DomainID = TDN.DomainID 
       LEFT OUTER JOIN Topology.Workgroup AS TWP 
         ON AET.AgentID = TWP.MachineID 
       LEFT OUTER JOIN Audit.EventDirectory AS AED 
         ON AET.EventID = AED.EventID 
WHERE  AET.TimeDetected >= '2012-06-07T04:00:00' 
       AND EXISTS(SELECT AET.EventID 
                  FROM   [Event].Class AS _EC 
                  WHERE  EXISTS(SELECT * 
                                FROM   Query.EventClass AS _ECQ 
                                WHERE  _ECQ.QueryID = 'C37D85D6-B725-4E98-A338-B8917CA5784F' 
                                       AND _ECQ.ProcessID = 0 
                                       AND StorageClassID = 0 
                                       AND _ECQ.EventClassID = _EC.EventClassID) 
                                       
                         AND _EC.EventClassID = AET.EventClassID) 
                    
                      
								  )
       
 ORDER BY ObjectName                   
                      
--ORDER  BY TimeDetected DESC, 
--          UserName DESC  

QuestionHow to get Renamed, Deleted, and Added Columns of the Table? Pin
Rohit Kesharwani5-Sep-12 4:25
Rohit Kesharwani5-Sep-12 4:25 
AnswerRe: How to get Renamed, Deleted, and Added Columns of the Table? Pin
David Mujica5-Sep-12 4:35
David Mujica5-Sep-12 4:35 
GeneralRe: How to get Renamed, Deleted, and Added Columns of the Table? Pin
PIEBALDconsult5-Sep-12 4:38
mvePIEBALDconsult5-Sep-12 4:38 
GeneralAnswered Pin
David Mujica5-Sep-12 9:23
David Mujica5-Sep-12 9:23 
GeneralRe: Answered Pin
PIEBALDconsult5-Sep-12 9:42
mvePIEBALDconsult5-Sep-12 9:42 
GeneralVery true Pin
David Mujica6-Sep-12 3:45
David Mujica6-Sep-12 3:45 
GeneralRe: Answered Pin
Eddy Vluggen5-Sep-12 23:42
professionalEddy Vluggen5-Sep-12 23:42 
GeneralCool Pin
David Mujica6-Sep-12 3:35
David Mujica6-Sep-12 3:35 
AnswerRe: How to get Renamed, Deleted, and Added Columns of the Table? Pin
PIEBALDconsult5-Sep-12 4:37
mvePIEBALDconsult5-Sep-12 4:37 
AnswerRe: How to get Renamed, Deleted, and Added Columns of the Table? Pin
Eddy Vluggen5-Sep-12 5:29
professionalEddy Vluggen5-Sep-12 5:29 
QuestionRe: How to get Renamed, Deleted, and Added Columns of the Table? Pin
Osama Bin Laden 20125-Sep-12 14:53
Osama Bin Laden 20125-Sep-12 14:53 
AnswerRe: How to get Renamed, Deleted, and Added Columns of the Table? Pin
PIEBALDconsult5-Sep-12 17:18
mvePIEBALDconsult5-Sep-12 17:18 
QuestionPersistent storage of measuring results Pin
LionAM3-Sep-12 22:57
LionAM3-Sep-12 22:57 
AnswerRe: Persistent storage of measuring results Pin
Mycroft Holmes4-Sep-12 0:40
professionalMycroft Holmes4-Sep-12 0:40 
GeneralRe: Persistent storage of measuring results Pin
LionAM4-Sep-12 4:37
LionAM4-Sep-12 4:37 
AnswerRe: Persistent storage of measuring results Pin
Shameel4-Sep-12 5:50
professionalShameel4-Sep-12 5:50 
AnswerRe: Persistent storage of measuring results Pin
PIEBALDconsult4-Sep-12 5:56
mvePIEBALDconsult4-Sep-12 5:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.