PC Review


Reply
Thread Tools Rate Thread

Better way to write this SQL?

 
 
Sarah Schreffler
Guest
Posts: n/a
 
      22nd Jun 2006
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

 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      22nd Jun 2006
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Offline file synchronization: no recycle bin sync & write back/not write through Joe Microsoft Windows 2000 File System 0 8th Jul 2006 11:27 AM
How to supress write/write password popup showing up when opening a document? Tomasz Jastrzebski Microsoft Powerpoint 0 21st Jun 2006 04:59 PM
Is there any way for System.IO.StreamWriter Write method to write out part of the string to file. such as if the machine is shut down half way through? or does the file not actually exist until the entire write is completed successfully. Daniel Microsoft Dot NET 1 7th Sep 2005 03:02 PM
Is there any way for System.IO.StreamWriter Write method to write out part of the string to file. such as if the machine is shut down half way through? or does the file not actually exist until the entire write is completed successfully. Daniel Microsoft C# .NET 2 7th Sep 2005 05:19 AM
Is there any way for System.IO.StreamWriter Write method to write out part of the string to file. such as if the machine is shut down half way through? or does the file not actually exist until the entire write is completed successfully. Daniel Microsoft Dot NET Framework 1 6th Sep 2005 09:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:21 AM.