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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Check if all rows meet condition

Author  Topic 

PHUser
Starting Member

11 Posts

Posted - 2010-05-14 : 12:08:16
ShippingDetails
ID IsShipped
1 1
2 1
3 0
4 0

I need to check if all rows returned in the where clause have IsShipped = 1. Let's say where clause filters ID 1 and 2.

How can this be acheived?

Sachin.Nand

2937 Posts

Posted - 2010-05-14 : 13:03:35
Why you want to check it again once you have put the condition IsShipped=1 in the where clause.

PBUH
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-14 : 13:03:43
just add

SELECT othercolumns
FROM
(
SELECT othercolumns, SUM(CASE WHEN IsShipped=0 THEN 1 ELSE 0 END) OVER () AS NonShipped
FROM Table
WHERE ID IN (1,2)
)t
WHERE NonShipped=0


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -