Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Select items used before a date but not after
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01635849
Message ID:
01635862
Vues:
38
>>I am working on a SQL Select where result is parts/items used prior to a certain date but not used after this date. Here is my attempt which does not seem to work
>>
>>
>>select * from part_file where part_pk in (select part_pk from part_used
>>where used_date !> '20100101' and used_date < '20100101')
>>
>>
>>How do I need to change the above SQL Select?
>
>
>
>select * from dbo.part_file p where not exists (select 1 from dbo.part_used pu where used_date >='20100101' and pu.part_pk = p.part_pk)
>
>Select all parts which were not used after 01-01-2010. (This may return parts which were not used at all)
>
>We can add the other part to this query to make sure the parts were used, e.g.
>
>
>select * from dbo.part_file p where not exists (select 1 from dbo.part_used pu where used_date >='20100101' and pu.part_pk = p.part_pk)
>and exists (select 1 from dbo.part_used pu where used_date <'20100101' and pu.part_pk = p.part_pk)
Thank you. The last of your SQL Select should do the job. But I will check it against my DB.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform