If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Help with SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-08-11, 07:01
ACarpenter ACarpenter is offline
Registered User
 
Join Date: Jun 2011
Posts: 2
Help with SQL

Hi can anybody help
I am trying to retrieve data based on a specific code andonly before a specific date for instance AZ before 17 - mar - 2012, however I have 10 different codes in the same field and 10 different dates.
If I put the following in it returns results

[ Sqle = Sqle & " and b.shipcode = 'VE' and b.departuredate < '10-Mar-2012'" ]

However when I create this it does not return any values


[ Sqle = Sqle & " and b.shipcode = 'VE' and b.departuredate < '10-Mar-2012'"
Sqle = Sqle & " and b.shipcode = 'AZ' and b.departuredate < '17-Mar-2012'" ]


I know there is probably a very simple solution but I am just not seeing it
Reply With Quote
  #2 (permalink)  
Old 06-08-11, 07:36
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
What kind of syntax is that? It is not SQL. Does the [...] denote an OR-condition? And what's the double-quote stuff and the & doing?
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 06-08-11, 07:41
ACarpenter ACarpenter is offline
Registered User
 
Join Date: Jun 2011
Posts: 2
sql help

The square brackets are not part of the code, this is part of an sql statement created in visual basic

Sqle = Sqle & " and b.shipcode like 'VE' and b.departuredate < '10-Mar-2012'"
Sqle = Sqle & " Order by b.openedby, b.opendate"

The double quotes are automatically applied by VB, but i basically want all results that have VE if depart before 10 march as well as all that have az if depart before 17 march and so on
Reply With Quote
  #4 (permalink)  
Old 06-08-11, 08:25
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,246
you dont' say what SQL engine you are using...
if thats JET / Access then your dates need to be encapsulated by # and use the US date format mm/dd/yyyy or the iso date format yyyy/mm/dd
eg
Code:
WHERE mydatecolumn < '#03/10/2012#'
..any error messages?
.. im not used to seeing VB statements enclosed by [ & ].. is that valid VB syntax. if its to denote the sql in your posting then prefix with [ c o d e ] and suffix with [ / c o d e ]
..natch remove the spaces before use
just a though have you actually checked there is data that matches those criteria?
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 06-08-11, 11:22
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
I'm sticking to SQL because this forum is about ISO/ANSI SQL and not some other syntax used by some products...

If you want to have all records "VE if depart before 10 march as well as all that have az if depart before 17 march", you'd have a query like this:
Code:
SELECT *
FROM   ...
WHERE  ( b.shipcode = 'VE' AND
          b.departuredate < '10-Mar-2012' ) OR
       ( b.shipcode = 'AZ' AND
          b.departuredate < '17-Mar-2012' )
The way you wrote it above:
Code:
[ Sqle = Sqle & " and b.shipcode = 'VE' and b.departuredate < '10-Mar-2012'"
Sqle = Sqle & " and b.shipcode = 'AZ' and b.departuredate < '17-Mar-2012'" ]
cannot work because you have two predicates "b.shipcode = 'VE' AND b.shipcode = 'AZ'" which are mutually exclusive - if one would evaluate to true for a row, the other would evaluate to false so that the ANDing of both predicates is always false.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #6 (permalink)  
Old 06-08-11, 12:02
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
Quote:
Originally Posted by healdem View Post
Code:
WHERE mydatecolumn < '#03/10/2012#'
Yes, except that the pound signs replace the single quotes:
Code:
WHERE mydatecolumn < #03/10/2012#
Quote:
im not used to seeing VB statements enclosed by [ & ]
The '&' is VBA's string concatenation operater -- the OP's building up a string of SQL. I think the open and close brackets are the OP's substitute for using '[code]' tags, which would be more appropriate.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On