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.
| Author |
Topic |
|
davidliv
Starting Member
45 Posts |
Posted - 2004-10-01 : 14:24:08
|
| I have 3 tables: tbl_branch; tbl_branchmargins; tbl_productstbl_branch is just a list of branch namestbl_products is a list of productstbl_branchmargins needs to contain a record for each product per branch.I need to query the tbl_branchmargins table to list the products which do not have records per branch. Meaning I need to identify products in which a single branch may not have a tbl_branchmagins record for.[u]This gives me products which don't exist in tbl_branchmargins:[u]SELECT p.product_id AS PIDFROM tbl_branchmargin bm RIGHT OUTER JOINtbl_product p ON bm.product_id = p.product_idWHERE (bm.product_id IS NULL) AND (p.product_active = 1)....but now I need to be sure that ALL of the branches have 1 record in branchmargin per product.Do I need to do multiple passes on this? |
|
|
VIG
Yak Posting Veteran
86 Posts |
Posted - 2004-10-01 : 15:14:47
|
| select full_bp.*from(select *from tbl_branch b,tbl_products pWHERE p.product_active = 1 ) full_bpleft join tbl_branchmargins bp on full_bp.branch=bp.branch and full_bp.product=bp.productwhere bp.branch is null |
 |
|
|
|
|
|