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 > comp.db.ms-sqlserver > Complicated query
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Complicated query

Réponse
 
LinkBack Outils de la discussion
Vieux 06/09/2007, 18h29   #1 (permalink)
Nick
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Complicated query

Hi,

I have two tables Trade table and Cons table. Records are inserted in
both the tables independent of each other. There are fields like
Exc_Ref, Qty, Date in both the tables.

I need to write a query which should give me records :

1. Where there is missing Exc_Ref value in either of the table. i.e.
If Trade table has a Exc_Ref value but missing in Cons table then that
record should be displayed. Similarly if Cons has a Exc_Ref value
which is not found in Trade table then that too should be displayed.

2. In case where both the tables have matching Exc_Ref data then it
should display the record only when the remaining column does not
match like Qty or Date.

Please me to resolve this complicated query.

Thanks
Nick

  Réponse avec citation
Vieux 06/09/2007, 20h06   #2 (permalink)
Roy Harvey
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Complicated query

Something along these lines should do it.

SELECT COALESCE(A.Exc_Ref, B.Exc_Ref) as Exc_Ref,
CASE WHEN B.Exc_Ref IS NULL
THEN 'Trade'
WHEN A.Exc_Ref IS NULL
THEN 'Cons'
ELSE ' <> '
End as Compare,
A.OtherCol1, B.OtherCol1,
....
A.OtherCol9, B.OtherCol9
FROM Trade as A
FULL OUTER
JOIN Cons as B
ON A.Exc_Ref = B.Exc_Ref
WHERE A.Exc_Ref IS NULL
OR B.Exc_Ref IS NULL
OR A.OtherCol1 <> B.OtherCol1
OR ...
OR A.OtherCol9 <> B.OtherCo9

This assumes that Exc_Ref is the unique key to both tables.

Roy Harvey
Beacon Falls, CT

On Thu, 06 Sep 2007 10:29:30 -0700, Nick
<nachiket.shirwalkar@gmail.com> wrote:

>Hi,
>
>I have two tables Trade table and Cons table. Records are inserted in
>both the tables independent of each other. There are fields like
>Exc_Ref, Qty, Date in both the tables.
>
>I need to write a query which should give me records :
>
>1. Where there is missing Exc_Ref value in either of the table. i.e.
>If Trade table has a Exc_Ref value but missing in Cons table then that
>record should be displayed. Similarly if Cons has a Exc_Ref value
>which is not found in Trade table then that too should be displayed.
>
>2. In case where both the tables have matching Exc_Ref data then it
>should display the record only when the remaining column does not
>match like Qty or Date.
>
>Please me to resolve this complicated query.
>
>Thanks
>Nick

  Réponse avec citation
Vieux 07/09/2007, 11h58   #3 (permalink)
Nick
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Complicated query

On 6 Sep, 20:06, Roy Harvey <roy_har...@snet.net> wrote:
> Something along these lines should do it.
>
> SELECT COALESCE(A.Exc_Ref, B.Exc_Ref) as Exc_Ref,
> CASE WHEN B.Exc_Ref IS NULL
> THEN 'Trade'
> WHEN A.Exc_Ref IS NULL
> THEN 'Cons'
> ELSE ' <> '
> End as Compare,
> A.OtherCol1, B.OtherCol1,
> ....
> A.OtherCol9, B.OtherCol9
> FROM Trade as A
> FULL OUTER
> JOIN Cons as B
> ON A.Exc_Ref = B.Exc_Ref
> WHERE A.Exc_Ref IS NULL
> OR B.Exc_Ref IS NULL
> OR A.OtherCol1 <> B.OtherCol1
> OR ...
> OR A.OtherCol9 <> B.OtherCo9
>
> This assumes that Exc_Ref is the unique key to both tables.
>
> Roy Harvey
> Beacon Falls, CT
>
> On Thu, 06 Sep 2007 10:29:30 -0700, Nick
>
>
>
> <nachiket.shirwal...@gmail.com> wrote:
> >Hi,

>
> >I have two tables Trade table and Cons table. Records are inserted in
> >both the tables independent of each other. There are fields like
> >Exc_Ref, Qty, Date in both the tables.

>
> >I need to write a query which should give me records :

>
> >1. Where there is missing Exc_Ref value in either of the table. i.e.
> >If Trade table has a Exc_Ref value but missing in Cons table then that
> >record should be displayed. Similarly if Cons has a Exc_Ref value
> >which is not found in Trade table then that too should be displayed.

>
> >2. In case where both the tables have matching Exc_Ref data then it
> >should display the record only when the remaining column does not
> >match like Qty or Date.

>
> >Please me to resolve this complicated query.

>
> >Thanks
> >Nick- Hide quoted text -

>
> - Show quoted text -


Thanks Roy ! Your solution is too perfect.

Thanks

  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 01h19.


Édité par : vBulletin® version 3.7.2
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
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08804 seconds with 11 queries