Query listing

  • Hi,

    SELECT

        tblActivityLog."ActivityLogID", tblActivityLog."ApplicantID", tblActivityLog."OrganisationID", tblActivityLog."ActivityID", tblActivityLog."DateTime", tblActivityLog."TransactionValue", tblActivityLog."ItemCount", tblActivityLog."Details", tblActivityLog."PassportPriceID", tblActivityLog."FrameworkID"

    FROM

        "Passports2"."dbo"."tblActivityLog" tblActivityLog

    where

        tblActivityLog."ActivityID"=4 and tblActivityLog."ApplicantID"=17816

     

    Above is the query i have..... but could someone help me where i need to query numerous applicants.... ie where applicantid= 17816, 17817, 17896, 17545 etc.....the applicant id's are not sequential.

    Kind Regards

    Jay

  • Jay

    First of all, get rid of those quoted identifiers: they're not necessary in this instance and they make your query difficult to read.

    If you obtain the list of applicants from another table, the best way to do this is to join to that table.  For example, if you have a table called Applicants, and the applicants you are interested in are over the age of 35, you could do something like this:

    SELECT

        L.ActivityLogID, L.ApplicantID, L.OrganisationID, L.ActivityID, L.DateTime, L.TransactionValue, L.ItemCount, L.Details, L.PassportPriceID, L.FrameworkID

    FROM

        Passports2.dbo.tblActivityLog L

    INNER JOIN

        Passports2.dbo.Applicants A

    ON

        L.ApplicantID = A.ApplicantID    

    WHERE

        L.ActivityID = 4

    AND

        A.Age > 35

    Otherwise, you can write your WHERE clause like this:

    WHERE ApplicantID IN (17816, 17817, 17896, 17545)

    [Note for those tempted to flame me on database design: this is for illustrative purposes only.  Of course I wouldn't design a table that had an Age column in it.]

    John

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply