tags:

views:

49

answers:

1

Table Name : Product Column : Product ID - A1, A2, A3, A4 , Product status (ordered (O).

I want to check If Product ID 'A1' product status is ordered or not and if ordered than other 3 ID (A2,A3,A4) should not be updated. In same way I want to check for remaining Product ID

A: 

Not sure what exactly you want, and most importantly how A1 is related to A2,A3 and A4. But if they are not really related, try this:

UPDATE  Product
SET     FieldX = ValueX,
        FieldY = ValueY
WHERE   ProductID IN (A2, A3, A4)
    AND NOT EXISTS (SELECT  * 
                    FROM    Product 
                    WHERE   ProductID = A1 
                        AND ProductStatus = 'Ordered'
                   )
van