Query to Select data from a single table with mutliple conditions

  • Hi,

    I have a table with the below column headings.

    Business UnitDocument IDDocument DateYearPeriodAccountDescrDeptProductProjectAnalysis CodeAffiliateCurrencyBase AmountUSD AmountLine DescrReferenceVendorVendor NameModuleDoc Line #AP Distrib Line #Post StatusSeq

    I need to pull data with the document date, account and dept.

    Where the document data would be the previous month,

    there would be multiple accounts: for eg: [FTS Yearly Query].Account >= 847000 and [FTS Yearly Query].Account <=847900 or [FTS Yearly Query].Account = 821000

    and multiple depts as well.

    and it do not get the required data.

    Could someone please help me.

  • renato_mech_334 (2/27/2013)


    Where the document data would be the previous month,

    there would be multiple accounts: for eg: [FTS Yearly Query].Account >= 847000 and [FTS Yearly Query].Account <=847900 or [FTS Yearly Query].Account = 821000

    and multiple depts as well.

    Hi:

    Your question is a little difficult to understand, unfortunately.

    But, here's a quick observation I'll share -- if the example criteria you've listed is taken from the sql code, then your results won't likely be as intended. From your example, I think you might try the following with parentheses:

    (

    [FTS Yearly Query].Account >= 847000 and [FTS Yearly Query].Account <=847900

    )

    or [FTS Yearly Query].Account = 821000

    --pete

  • Hi Pete,

    Thanks for the reply.

    I figured it out by using it in this format.

    WHERE ([FTS Yearly Query].Dept = "3310" ) and ( ([FTS Yearly Query].Account >= 847000 and [FTS Yearly Query].Account <=847900 or [FTS Yearly Query].Account = 821000) and (Year([FTS Yearly Query].[Document Date])* 12 + DatePart("m", [FTS Yearly Query].[Document Date]) = Year(Date())* 12 + DatePart("m", Date()) - 1)

    Regards,

    Renato

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

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