Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Syntax help
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01400647
Message ID:
01400671
Vues:
26
>Hi All,
>
>I have the following tables:
>Table A
>
>EDP          PODate
>123	05-03-2009
>456     05-01-2009
>
>
>Table B
>
>EDP CaptureDate     Alert
>123   05-03-2009	Low
>123   04-29-2009	BO
>456   04-28-2009	Low
>456   04-25-2009	Zero
>
>
>I need to join those two tables on EDP and return EDP from Table A along with its corresponding Alert based on the following:
>1. PODate = CaptureDate
>2. If there is no match on the dates I need to find the closest CaptureDate to PODate and get the Alert
>
>Is there a way to do this in one query?
>
>Expected Results:
>
>EDP	Alert
>123	Low
>456     Low
>
>
>
>Thank you,
>daniel


Closest UP or Closest DOWN?
What if you have:
456   04-28-2009	Low
456   04-25-2009	Zero
456   05-10-2009	Something
What record should be chosen?
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform