Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI

I am trying to do a count of productserials from a table.

I currently have a view called listStages which is a union statement of the following tables(receive,soak,test,repair,software, dispatch)

each table in the brackets has a passfail.pass = 1 fail = 0

ListStages shows each product and if it was passed or failed at a stage.

I would like to know how would i be able to select the products which only have a pass(1) on each table and if it has a fail then it should not show in my records which are returned by the query
Posted
Updated 7-Mar-13 22:23pm
v2
Comments
Davidduraisamy 8-Mar-13 4:24am    
Restrict the condition in where clause as pass=1
isi19 8-Mar-13 4:39am    
See the only thing is that the product has to be passed to be dispatched , the process will follow Rceive pass --> soak pass --> test pass --> dispatch

if there is a fail

Rceive pass--> soak fail--> repair Pass--> soak pass--> test pass--> dispatch

now i need to select only the products that follow the 1st process.
if i select * from ListStage where passfail = 1 then it will return the value of the product which had a repair. and i want it to show only the products which do not have a repair
Davidduraisamy 8-Mar-13 4:46am    
hey if you are applying where condition in all table den how fail condition will come

Hi,

Simplest way is to use pass = 1 in where condition for all tables
or use a common table expression , write your union query inside it and use where condition at output
 
Share this answer
 
I'm not sure wjat you want to do, but based on your comment:
Rceive pass--> soak fail--> repair Pass--> soak pass--> test pass--> dispatch
now i need to select only the products that follow the 1st process. if i select * from ListStage where passfail = 1 then it will return the value of the product which had a repair. and i want it to show only the products which do not have a repair

i recommend you to do something like this:
SQL
SELECT LS.*
FROM listStages AS LS LEFT JOIN Rceive AS RC ON LC.ProductID = RC.ProductID
WHERE RC.Pass=1

or
SQL
SELECT *
FROM listStages 
WHERE ProductID IN (
    SELECT ProductID
    FROM Rceive
    WHERE Pass=1)
 
Share this answer
 
As per my understanding ... you want this ....

SQL
Select stage,product,SUM(CAST(passfail  AS numeric))  from listStages  
GROUP BY stage,product
Having SUM(CAST(passfail AS numeric)) = COUNT(1)  
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900