Re: Mailmerge, querystring and (un)logical SQL (Word 2003)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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



.



Relevant Pages

  • Mailmerge, querystring and (un)logical SQL (Word 2003)
    ... I have the following problem related to mailmerge, QueryString command ... In other words parentheses are ignored in this logic sentence and get ... Is there any way to force Word to accept the "parenthesis logic"? ... I am enclosing the part of my real code which is a subject of my ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Huge problem and no idea...
    ... if you want a parenthesis around an equation number you should use ... the command \eqref from amsmath. ... The problem here is that the reference number is 2.1 and is inserted ...
    (comp.text.tex)
  • Re: Extracting the String Between Two Patterns
    ... command can extract the string between the parenthesis in following ... I can use awk to find the index of the parenthesis. ... command that can do this for me in one swoop. ...
    (comp.unix.shell)
  • Re: Extracting the String Between Two Patterns
    ... command can extract the string between the parenthesis in following ... fileName ... I can use awk to find the index of the parenthesis. ... command that can do this for me in one swoop. ...
    (comp.unix.shell)
  • Re: symbolic solve
    ... I use this command Is it correct? ... I think you forgot the leading parenthesis on the denominator for ... Then removed the trailing parenthesis, as well, here. ... How can I plugging my resuls? ...
    (comp.soft-sys.matlab)