Re: Mailmerge, querystring and (un)logical SQL (Word 2003)
- From: "Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 29 Jun 2006 13:01:39 +0200
Try:
SELECT *
FROM x
WHERE (((Field_1)="A") AND ((Field_2)="D") AND ((Field_3)<="E") AND
((Field_3)>="F")) OR (((Field_1)="B") AND ((Field_2)="D") AND
((Field_3)<="E") AND ((Field_3)>="F")) OR (((Field_1)="C") AND
((Field_2)="D") AND ((Field_3)<="E") AND ((Field_3)>="F")) ORDER BY field _4
ASC
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"FP" <fp@xxxxxxxxx> wrote in message
news:1151574312.724062.292180@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
My name is Feliks, I am from Poland and this is my first post to the
group.
I have the following problem related to mailmerge, QueryString command
and SQL sentence in Word 2003.
In my code I need to perform the following SQL operation with
ActiveDocument.MailMerge.DataSource.QueryString command:
SELECT * FROM x WHERE (field_1 = A OR field _1 = B OR field _1 = C) AND
field _2 = D AND field _3 <= E and field_3 >=F ORDER BY field_4 ASC
The command is executed without any problems however records retrieved
by the command do not match the above criteria. Instead I get records
which match the following:
SELECT * FROM x WHERE field _1 = A OR field_1 = B OR field _1 = C AND
field _2 = D AND field _3 = E ORDER BY field _4 ASC
In other words parentheses are ignored in this logic sentence and get
completely different set of records as it is supposed to be.
I tried different combinations a) with "(field_1 =A OR ... )" part
at the end (before ORDER), b) with additional parenthesis embracing the
part between WHERE and ORDER etc, the result is always not as expected.
Is there any way to force Word to accept the "parenthesis logic"?
Has anyone a clue how to do it?
I am enclosing the part of my real code which is a subject of my
question (and frustration):
airport_query = " (`Airport` = 'Berlin' OR `Airport` = 'Szczecin' OR
`Airport` = 'Szczecin/Berlin') AND "
st_d = Year(start_dt) & "-" & Month(start_dt) & "-" & Day(start_dt)
en_d = Year(end_dt) & "-" & Month(end_dt) & "-" & Day(end_dt)
vsl = Me.tbVessel.Text
qs = "SELECT * FROM `non-NISSeafarersQuery` WHERE" & airport_query &
"(`VslName` = '" & vsl & "') And (`SignOnDate` <= #" & en_d & "#) And
(`SignOnDate` >= #" & st_d & "#) ORDER BY `City` ASC"
ActiveDocument.MailMerge.DataSource.QueryString = qs & ""
Any comment will be highly appreciated.
Regards,
FP
.
- References:
- Prev by Date: Mailmerge, querystring and (un)logical SQL (Word 2003)
- Next by Date: Merging data into several forms
- Previous by thread: Mailmerge, querystring and (un)logical SQL (Word 2003)
- Next by thread: Re: Mailmerge, querystring and (un)logical SQL (Word 2003)
- Index(es):
Relevant Pages
|