Mensaje
De
13/01/2017 13:19:46
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
a
13/01/2017 09:40:22
General information
Foro:
Microsoft SQL Server
Category:
Sintáxis SQL
Environment versions
SQL Server:
SQL Server 2014
OS:
Windows 8.1
Network:
Windows Server 2012
Miscellaneous
ID de la conversación:
01646648
ID del mensaje:
01646656
Views:
40
>I have a select such as:
>
>
>SELECT Invoice.Numero
> FROM Invoice
> WHERE Invoice.NoClient IN (5,44,52,54,55,57,58,59,60,61,62,63,64,65,66,67,68,70,71,72,73,69,74,75,76,77,78,80)
>
>
>Then, we could have another one such as:
>
>
>SELECT Invoice.Numero
> FROM Invoice
> WHERE Invoice.NoClient2 IN (79)
>
>
>I need to combine both selects into one which would return only the records where Invoice.NoClient and Invoice.NoClient2 match in both.
>
>For example, in the example above, none would be returned.
>
>However, if I would have this:
>
>
>SELECT Invoice.Numero
> FROM Invoice
> WHERE Invoice.NoClient IN (5,44,52,54,55,57,58,59,60,61,62,63,64,65,66,67,68,70,71,72,73,69,74,75,76,77,78,80)
>
>
>Then, we could have another one such as:
>
>
>SELECT Invoice.Numero
> FROM Invoice
> WHERE Invoice.NoClient2 IN (5,44,79)
>
>
>Then, as 5 and 44 match both, this means I would have some results.
>
>What would be the simplest way to achieve that?


You can simply use AND:
SELECT Invoice.Numero
 FROM Invoice
 WHERE Invoice.NoClient = Invoice.NoClient2 AND
 Invoice.NoClient IN (5,44,52,54,55,57,58,59,60,61,62,63,64,65,66,67,68,70,71,72,73,69,74,75,76,77,78,80)
AND Invoice.NoClient2 IN (79)
Update: Not sure I got you right. Discard.
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Responder
Mapa
Ver