PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > Double results with my sql query?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Double results with my sql query?

Réponse
 
LinkBack Outils de la discussion
Vieux 17/07/2008, 18h46   #1
Hidarisei
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Double results with my sql query?

Hello!

I'm in the toner cartridge recycling/manufacturing business and I'm building
a software application to control our inventory. I'm having this problem and
I've tried for several months to solve it without success.

Here are my tables:

=============

CARTRIDGE_BRANDS
-----------------
PKey
Name

CARTRIDGES
-----------------
PKey
Name
Brand_FKey

CARTRIDGE_TYPES >> Virgin / Non-Virgin / Not-Ours
-----------------
PKey
Name

EMPTIES >> We deal with empty toner cartridges
-----------------
PKey
Cartridge_FKey
CartridgeType_FKey

SUPPLIERS
-----------------
PKey
Name

SUPPLIER_ITEMS >> Many suppliers can send us the same product
------------------
PKey
Name
Supplier_FKey
Empty_FKey

Special Note : I store information about quantities through another table
that holds the actual locations and quantities of all empty cartridges.

EMPTIES_STORAGES
-------------------
PKey
Qty
Empty_FKey
Supplier_FKey
Letter_FKey >> Zone - Rack - Letter ( D - 21 - F )

==============

I NEED TO FETCH A LIST OF EMPTIES
Empty_Name / Empty_Type / Qty / Supplier

Q : What should be the SQL statement to retrieve this info? I want to group
all the rows per suppliers... ??????????

Easy you say.... Well everything is good until I have the following:
SupplierEmpty 1 = HP 4500 Black (Virgin) From Supplier 1 (50 per box)
SupplierEmpty 2 = HP 4500 Black (Virgin) From Supplier 1 (100 per box)
SupplierEmpty 3 = HP 4500 Black (Non-Virgin) From Supplier 1 (50 per box)

The fault condition is when I have 2 supplier empties of the same type and
another one of a different type for the same empty. I get the Virgin empty
showing twice in the sql result.

==============================================
SELECT CartridgeBrands.CartBrand_Name,
Cartridges.Cartridge_Name,
Cartridges.CartBrand_NRI,
CartridgeBrands.CartBrand_Name,
Empties.Empty_NRI,
Empties.Cartridge_NRI,
Empties.Empty_PICode,
Empties.Empty_Desc,
Empties.CartType_NRI,
CartTypes.CartType_Name,
SupplierEmpties.Supplier_NRI,
Suppliers.Supplier_Name
FROM CartridgeBrands
INNER JOIN Cartridges ON CartridgeBrands.CartBrand_NRI =
Cartridges.CartBrand_NRI
INNER JOIN Empties ON Cartridges.Cartridge_NRI = Empties.Cartridge_NRI
INNER JOIN CartTypes ON Empties.CartType_NRI = CartTypes.CartType_NRI
INNER JOIN SupplierEmpties ON Empties.Empty_NRI = SupplierEmpties.Empty_NRI
INNER JOIN Suppliers ON SupplierEmpties.Supplier_NRI =
Suppliers.Supplier_NRI
WHERE Cartridges.CartBrand_NRI = 3 AND Empties.Cartridge_NRI = 81
ORDER BY CartridgeBrands.CartBrand_Name,
Cartridges.Cartridge_Name,
Empties.CartType_NRI,
Suppliers.Supplier_Name ASC
================================================== =====

!!!!!

You can email me for the structure of my database (JPEG File)
stephane@premiere-supplies.com
  Réponse avec citation
Vieux 18/07/2008, 09h49   #2
Ricardo Junquera
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: Double results with my sql query?

Hi

try
INNER JOIN --> LEFT OUTER JOIN ¿?

--
Ricardo Junquera
Consultor Business Intelligence

BG&S Online Consultores
Ganadora del Premio Microsoft Business Awards 2008.
Partner de Soluciones : Satisfacción de Cliente.



"Hidarisei" wrote:

> Hello!
>
> I'm in the toner cartridge recycling/manufacturing business and I'm building
> a software application to control our inventory. I'm having this problem and
> I've tried for several months to solve it without success.
>
> Here are my tables:
>
> =============
>
> CARTRIDGE_BRANDS
> -----------------
> PKey
> Name
>
> CARTRIDGES
> -----------------
> PKey
> Name
> Brand_FKey
>
> CARTRIDGE_TYPES >> Virgin / Non-Virgin / Not-Ours
> -----------------
> PKey
> Name
>
> EMPTIES >> We deal with empty toner cartridges
> -----------------
> PKey
> Cartridge_FKey
> CartridgeType_FKey
>
> SUPPLIERS
> -----------------
> PKey
> Name
>
> SUPPLIER_ITEMS >> Many suppliers can send us the same product
> ------------------
> PKey
> Name
> Supplier_FKey
> Empty_FKey
>
> Special Note : I store information about quantities through another table
> that holds the actual locations and quantities of all empty cartridges.
>
> EMPTIES_STORAGES
> -------------------
> PKey
> Qty
> Empty_FKey
> Supplier_FKey
> Letter_FKey >> Zone - Rack - Letter ( D - 21 - F )
>
> ==============
>
> I NEED TO FETCH A LIST OF EMPTIES
> Empty_Name / Empty_Type / Qty / Supplier
>
> Q : What should be the SQL statement to retrieve this info? I want to group
> all the rows per suppliers... ??????????
>
> Easy you say.... Well everything is good until I have the following:
> SupplierEmpty 1 = HP 4500 Black (Virgin) From Supplier 1 (50 per box)
> SupplierEmpty 2 = HP 4500 Black (Virgin) From Supplier 1 (100 per box)
> SupplierEmpty 3 = HP 4500 Black (Non-Virgin) From Supplier 1 (50 per box)
>
> The fault condition is when I have 2 supplier empties of the same type and
> another one of a different type for the same empty. I get the Virgin empty
> showing twice in the sql result.
>
> ==============================================
> SELECT CartridgeBrands.CartBrand_Name,
> Cartridges.Cartridge_Name,
> Cartridges.CartBrand_NRI,
> CartridgeBrands.CartBrand_Name,
> Empties.Empty_NRI,
> Empties.Cartridge_NRI,
> Empties.Empty_PICode,
> Empties.Empty_Desc,
> Empties.CartType_NRI,
> CartTypes.CartType_Name,
> SupplierEmpties.Supplier_NRI,
> Suppliers.Supplier_Name
> FROM CartridgeBrands
> INNER JOIN Cartridges ON CartridgeBrands.CartBrand_NRI =
> Cartridges.CartBrand_NRI
> INNER JOIN Empties ON Cartridges.Cartridge_NRI = Empties.Cartridge_NRI
> INNER JOIN CartTypes ON Empties.CartType_NRI = CartTypes.CartType_NRI
> INNER JOIN SupplierEmpties ON Empties.Empty_NRI = SupplierEmpties.Empty_NRI
> INNER JOIN Suppliers ON SupplierEmpties.Supplier_NRI =
> Suppliers.Supplier_NRI
> WHERE Cartridges.CartBrand_NRI = 3 AND Empties.Cartridge_NRI = 81
> ORDER BY CartridgeBrands.CartBrand_Name,
> Cartridges.Cartridge_Name,
> Empties.CartType_NRI,
> Suppliers.Supplier_Name ASC
> ================================================== =====
>
> !!!!!
>
> You can email me for the structure of my database (JPEG File)
> stephane@premiere-supplies.com

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h08.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,26703 seconds with 10 queries