Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TSQL 2000/2005 Query Conundrum
Message
De
10/12/2007 11:19:12
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01274411
Message ID:
01274449
Vues:
9
You're right. I should have caught that. Thanks so much Sergey!


>Why repeat the same conditions twice? Try
>
>SELECT i.* from table1 i
>	  WHERE (i.field1 = 'FA' and field2 IN('AAA','BBB') AND i.field3 = 0)
>       		AND NOT EXISTS (SELECT * from table3 a WHERE a.table2id = i.table2id AND a.field4 = i.field4))
>  			AND (EXISTS (SELECT * from table2 s WHERE s.table2id = i.table2id AND s.fielda <> 'X' AND s.fieldb <> 'I')
>    				OR NOT EXISTS (SELECT * from table2 s WHERE s.table2id = i.table2id))
>
>>I think this works:
>>
>>SELECT i.* from table1 i
>>  WHERE (((i.field1 = 'FA' and (field2 = 'AAA' or field2 = 'BBB') AND i.field3 = 0)
>>     AND EXISTS (select * from table2 s where s.table2id = i.table2id AND s.fielda <> 'X'
>>                    AND s.fieldb <> 'I')
>>     AND NOT EXISTS (SELECT * from table3 a where a.table2id = i.table2id
>>                      AND a.field4 = i.field4))
>>    OR
>>      ((i.field1 = 'FA' and (field2 = 'AAA' or field2 = 'BBB') AND i.field3 = 0)
>>            AND NOT EXISTS (select * from table2 s where s.table2id = i.table2id)
>>            AND NOT EXISTS (SELECT * from table3 a where a.table2id = i.table2id
>>                             AND a.field4 = i.field4)))
>>
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform