Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Self join challenge..
Message
De
10/03/2003 18:32:44
 
 
À
08/03/2003 15:25:05
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00762414
Message ID:
00763994
Vues:
16
Mike,

Thanks... I got a correct query from this, it is very close.

BOb


>Assuming that the table is called Audit, I'm thinking of something like this
>
>SELECT
> ...
>FROM
> Audit a
> LEFT OUTER JOIN Audit pa ON a.eeID = pa.eeID
>WHERE
> pa.eeID IN (SELECT TOP 1 eeID FROM Audit a1 WHERE a1.eeID = a.eeID AND audit_datetime < a.audit_datetime)
>
>-Mike
>
>audit_id
>, audit_datetime
>, audit_imageType
>, audit_username
>, ee_id
>, empnum
>, fname
>, mname
>, lname
>
>So, I want to end up with a return of:
>
>audit_datetime
>,audit_username
>,ee_id_old
>,ee_id_new
>,empnum_old
>,empnum_new
>,fname_old
>,fname_new
>
>
>
>
>
>
>
>>>Do you want a clue or the answer? The clue is in rewording the problem:
>>>
>>>I want the first record that comes before the current audit record for the same ID.
>>>
>>>-Mike
>>
>>Right, and I have been able to write a query to get the audit_id of the record that comes before a specific audit_id record, but I am not sure how to write it to return a rs that meets a certain date range. I'd hate to resort to a cursor.
>>
>>So, I guess I want the answer.
>>
>>BOb
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform