Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

Better way to write this SQL?

Discussion in 'Information Technology' started by Sarah Schreffler, Jul 28, 2006.

Tags:
  1. Sarah Schreffler

    Sarah Schreffler
    Expand Collapse
    Guest

    Access automatically writes this SQL when I make the query view look
    like what I want:
    INSERT INTO trptDeliverable ( lnkDeliverableID, dtmReportRun, txtField
    )
    SELECT tblDeliverable.DeliverableID, #6/21/2006 16:18:34# AS
    DateReportRan, 'QC' AS Expr2
    FROM tblDeliverable
    WHERE (((tblDeliverable.QCcompleteDate) Is Null) AND
    ((tblDeliverable.DateDeliverableAdded)>#6/30/2006 10:4:31#) AND
    ((tblDeliverable.QCreviewDate)<=#6/30/2006#)) OR
    (((tblDeliverable.QCcompleteDate) Is Null) AND
    ((tblDeliverable.DateDeliverableAdded)>#6/30/2006 10:4:31#) AND
    ((tblDeliverable.QCreviewDate) Between #6/30/2006 10:4:31# And
    #6/30/2006 16:20:33#));


    WHERE clauses referred to:
    Criteria 1 = ((tblDeliverable.QCcompleteDate) Is Null)
    Criteria 2 = ((tblDeliverable.DateDeliverableAdded)>#6/30/2006
    10:4:31#)
    Criteria 3 = ((tblDeliverable.QCreviewDate)<=#6/30/2006#))
    Criteria 4 = ((tblDeliverable.QCreviewDate) Between #6/30/2006 10:4:31#
    And #6/30/2006 16:20:33#)

    What I want, conceptually speaking is WHERE (Criteria 1 and Criteria 2
    and (Criteria 3 or Criteria 4)) -- But when I put those parenthese in
    that way, it doesn't isolate the Criteria out the way I want.

    Is there any way to write this SQL statement where I don't have to
    write it
    WHERE (Criteria 1 and Criteria 2 and Criteria 3 or Criteria 1 and
    Criteria 2 and Criteria 4)?

    This is a SQL statement being created in code and I'd rather it be as
    easy to read as possible. But Access does not seem to be reading the
    parenthesse as I would expect.

    Thanks

    --Sarah Schreffler
     
  2. Loading...

    Similar Threads Forum Date
    How Can We Be Better Sikhs? Questions and Answers Apr 15, 2017
    Is It Better To Just Insulate Yourself In Your Own World? Blogs Nov 5, 2016
    Getting Something Off Your Chest Always Makes You Feel Better Hard Talk May 15, 2016
    Good news! getting better Bad news! so is he Blogs Oct 17, 2015
    Christianity How Pope Francis made me better appreciate my Sikh faith (COMMENTARY) Interfaith Dialogues Sep 27, 2015

  3. Douglas J. Steele

    Douglas J. Steele
    Expand Collapse
    Guest

    WHERE ((tblDeliverable.QCcompleteDate Is Null) AND
    (tblDeliverable.DateDeliverableAdded>#6/30/2006 10:4:31#) AND
    ((tblDeliverable.QCreviewDate<=#6/30/2006#) OR
    (tblDeliverable.QCreviewDate Between #6/30/2006 10:4:31# And
    #6/30/2006 16:20:33#)))

    or, more simply,

    WHERE (tblDeliverable.QCcompleteDate Is Null AND
    tblDeliverable.DateDeliverableAdded>#6/30/2006 10:4:31# AND
    (tblDeliverable.QCreviewDate<=#6/30/2006# OR
    tblDeliverable.QCreviewDate Between #6/30/2006 10:4:31# And
    #6/30/2006 16:20:33#)



    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no private e-mails, please)


    "Sarah Schreffler" <sarah.schreffler@gmail.com> wrote in message
    news:1150932740.059503.134990@g10g2000cwb.googlegroups.com...
    > Access automatically writes this SQL when I make the query view look
    > like what I want:
    > INSERT INTO trptDeliverable ( lnkDeliverableID, dtmReportRun, txtField
    > )
    > SELECT tblDeliverable.DeliverableID, #6/21/2006 16:18:34# AS
    > DateReportRan, 'QC' AS Expr2
    > FROM tblDeliverable
    > WHERE (((tblDeliverable.QCcompleteDate) Is Null) AND
    > ((tblDeliverable.DateDeliverableAdded)>#6/30/2006 10:4:31#) AND
    > ((tblDeliverable.QCreviewDate)<=#6/30/2006#)) OR
    > (((tblDeliverable.QCcompleteDate) Is Null) AND
    > ((tblDeliverable.DateDeliverableAdded)>#6/30/2006 10:4:31#) AND
    > ((tblDeliverable.QCreviewDate) Between #6/30/2006 10:4:31# And
    > #6/30/2006 16:20:33#));
    >
    >
    > WHERE clauses referred to:
    > Criteria 1 = ((tblDeliverable.QCcompleteDate) Is Null)
    > Criteria 2 = ((tblDeliverable.DateDeliverableAdded)>#6/30/2006
    > 10:4:31#)
    > Criteria 3 = ((tblDeliverable.QCreviewDate)<=#6/30/2006#))
    > Criteria 4 = ((tblDeliverable.QCreviewDate) Between #6/30/2006 10:4:31#
    > And #6/30/2006 16:20:33#)
    >
    > What I want, conceptually speaking is WHERE (Criteria 1 and Criteria 2
    > and (Criteria 3 or Criteria 4)) -- But when I put those parenthese in
    > that way, it doesn't isolate the Criteria out the way I want.
    >
    > Is there any way to write this SQL statement where I don't have to
    > write it
    > WHERE (Criteria 1 and Criteria 2 and Criteria 3 or Criteria 1 and
    > Criteria 2 and Criteria 4)?
    >
    > This is a SQL statement being created in code and I'd rather it be as
    > easy to read as possible. But Access does not seem to be reading the
    > parenthesse as I would expect.
    >
    > Thanks
    >
    > --Sarah Schreffler
    >
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page