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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 query only show errors

Author  Topic 

M_henriksen
Starting Member

5 Posts

Posted - 2013-10-14 : 10:07:27
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 result
server group error code
lion gr5 23
lion gr5 0
bird gr8 27
bird gr8 27

This means that in the example above I would like to have a result like:

server group error code
bird gr8 27

If 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,errorcode
FROM
(
SELECT server,group,errorcode,
SUM(CASE WHEN code=0 THEN 1 ELSE 0 END) OVER (PARTITION BY server,group) AS Cnt
FROM table
)t
WHERE Cnt = 0


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-14 : 10:39:33
[code]SELECT * FROM Tbl a
WHERE NOT EXISTS (SELECT * FROM Tbl b
WHERE b.[SERVER] = a.[SERVER] AND b.[GROUP] = a.[GROUP] AND b.errorcode = 0);[/code]
Go to Top of Page

M_henriksen
Starting Member

5 Posts

Posted - 2013-10-15 : 12:16:34
It works :)
Thanks for the help to both of you.
Go to Top of Page
   

- Advertisement -