Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I am very very new to SQL and of course got a a problem with a query now.I have some different backup jobs and want a daily report for the past 24 hours with status only for jobs there don't have a successful backup job. (error code 0 = successful)sql query resultserver group error codelion gr5 23lion gr5 0bird gr8 27bird gr8 27This means that in the example above I would like to have a result like:server group error codebird gr8 27If I have not explained it well enough just say so.BR Morten
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2013-10-14 : 10:14:52
sound like this to me
SELECT server,group,errorcodeFROM(SELECT server,group,errorcode,SUM(CASE WHEN code=0 THEN 1 ELSE 0 END) OVER (PARTITION BY server,group) AS CntFROM table)tWHERE Cnt = 0
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
James K
Master Smack Fu Yak Hacker
3873 Posts
Posted - 2013-10-14 : 10:39:33
[code]SELECT * FROM Tbl aWHERE NOT EXISTS (SELECT * FROM Tbl bWHERE b.[SERVER] = a.[SERVER] AND b.[GROUP] = a.[GROUP] AND b.errorcode = 0);[/code]