A Microsoft Office (Excel, Word) forum. OfficeFrustration

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   Home » OfficeFrustration forum » Microsoft Word » Mailmerge
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Statement parameter in Mailmerge.OpenDataSource



 
 
Thread Tools Display Modes
  #1  
Old April 25th, 2005, 09:22 AM
Christof Nordiek
external usenet poster
 
Posts: n/a
Default Statement parameter in Mailmerge.OpenDataSource

i'm trying to make some MailMerge by automating word2003.
If i call MailMerge.OpenDataSource, what can i pass for the Satement
Parameter?
For Connectioninformation i'm using a *.odc file, wich connects to a
SQL-Server.
The name of the odc-file i pass as the Name parameter.

when I try
SELECT * FROM MyView
it fails.

SELECT * FROM "MyView"
succeeds.

Also passing the name of the view suceeds only with quotationmarks

What i'm trying to do is, passing a statement calling a table-valued
Function with parameters and/or a statement with a where clause containing
Filterconditions.

Does anyone know, how to do this?

Thanks



  #2  
Old April 25th, 2005, 12:36 PM
Peter Jamieson
external usenet poster
 
Posts: n/a
Default

You can certainly pass an SQL SELECT statement with a WHERE clause. Getting
the syntax right can be difficult, as you have discovered. What I find
generally works is
a. quoting table and column names. I think it is clearer to use `` or []
rather than "" but it may be less standard these days
b. aliasing tables - even when aliasing should not be syntactiaclly
required - and always using the alias names when referencing individual
columns
c. using single quotes ' ' as text literal delimiters
e.g. (not tested - you'll need to play around to check)

SELECT [MV].* FROM [MyView] MV WHERE [MV].[MyColumn] = 'abc'

You may also be able to pass a call to a Transact-SQL procedure using the
old ODBC escape syntax which looks something like

{ call functionname(p1,p2) }

You may be able to find out more about that in SQL Server Books Online.
However, I have had a mixed experience using that approach in the past
because, for example, procedures that return multiple results do not seem to
work.

Peter Jamieson

"Christof Nordiek" wrote in message
...
i'm trying to make some MailMerge by automating word2003.
If i call MailMerge.OpenDataSource, what can i pass for the Satement
Parameter?
For Connectioninformation i'm using a *.odc file, wich connects to a
SQL-Server.
The name of the odc-file i pass as the Name parameter.

when I try
SELECT * FROM MyView
it fails.

SELECT * FROM "MyView"
succeeds.

Also passing the name of the view suceeds only with quotationmarks

What i'm trying to do is, passing a statement calling a table-valued
Function with parameters and/or a statement with a where clause containing
Filterconditions.

Does anyone know, how to do this?

Thanks





  #3  
Old April 25th, 2005, 12:41 PM
Peter Jamieson
external usenet poster
 
Posts: n/a
Default

OH yes, also SQLStatement has a maximum length of around 255 characters. You
/may/ be able to get more by using SQLStatement1 as well, in which case the
complete statement is the concatenation of SQLStatement and SQLStatement1
and you may get up to around 511 characters, but it does vary depending on
the version of Word, the data source and the connection method.

Peter Jamieson
"Peter Jamieson" wrote in message
...
You can certainly pass an SQL SELECT statement with a WHERE clause.
Getting the syntax right can be difficult, as you have discovered. What I
find generally works is
a. quoting table and column names. I think it is clearer to use `` or []
rather than "" but it may be less standard these days
b. aliasing tables - even when aliasing should not be syntactiaclly
required - and always using the alias names when referencing individual
columns
c. using single quotes ' ' as text literal delimiters
e.g. (not tested - you'll need to play around to check)

SELECT [MV].* FROM [MyView] MV WHERE [MV].[MyColumn] = 'abc'

You may also be able to pass a call to a Transact-SQL procedure using the
old ODBC escape syntax which looks something like

{ call functionname(p1,p2) }

You may be able to find out more about that in SQL Server Books Online.
However, I have had a mixed experience using that approach in the past
because, for example, procedures that return multiple results do not seem
to work.

Peter Jamieson

"Christof Nordiek" wrote in message
...
i'm trying to make some MailMerge by automating word2003.
If i call MailMerge.OpenDataSource, what can i pass for the Satement
Parameter?
For Connectioninformation i'm using a *.odc file, wich connects to a
SQL-Server.
The name of the odc-file i pass as the Name parameter.

when I try
SELECT * FROM MyView
it fails.

SELECT * FROM "MyView"
succeeds.

Also passing the name of the view suceeds only with quotationmarks

What i'm trying to do is, passing a statement calling a table-valued
Function with parameters and/or a statement with a where clause
containing
Filterconditions.

Does anyone know, how to do this?

Thanks







  #4  
Old April 25th, 2005, 01:54 PM
Christof Nordiek
external usenet poster
 
Posts: n/a
Default

Hi Peter

OK, i now can use a statement with a where-clause for filtering. The next
thing i have to do is, call a table-valued function and give it an actual
value for a parameter.

SELECT * FROM MyFuction(58)

works from QueryAnalyzer and from .NET-application but not for Mail-Merge.
Do You know, how to do this??

Thanks

"Peter Jamieson" schrieb im Newsbeitrag
...
You can certainly pass an SQL SELECT statement with a WHERE clause.
Getting the syntax right can be difficult, as you have discovered. What I
find generally works is
a. quoting table and column names. I think it is clearer to use `` or []
rather than "" but it may be less standard these days
b. aliasing tables - even when aliasing should not be syntactiaclly
required - and always using the alias names when referencing individual
columns
c. using single quotes ' ' as text literal delimiters
e.g. (not tested - you'll need to play around to check)

SELECT [MV].* FROM [MyView] MV WHERE [MV].[MyColumn] = 'abc'

You may also be able to pass a call to a Transact-SQL procedure using the
old ODBC escape syntax which looks something like

{ call functionname(p1,p2) }

You may be able to find out more about that in SQL Server Books Online.
However, I have had a mixed experience using that approach in the past
because, for example, procedures that return multiple results do not seem
to work.

Peter Jamieson

"Christof Nordiek" wrote in message
...
i'm trying to make some MailMerge by automating word2003.
If i call MailMerge.OpenDataSource, what can i pass for the Satement
Parameter?
For Connectioninformation i'm using a *.odc file, wich connects to a
SQL-Server.
The name of the odc-file i pass as the Name parameter.

when I try
SELECT * FROM MyView
it fails.

SELECT * FROM "MyView"
succeeds.

Also passing the name of the view suceeds only with quotationmarks

What i'm trying to do is, passing a statement calling a table-valued
Function with parameters and/or a statement with a where clause
containing
Filterconditions.

Does anyone know, how to do this?

Thanks







  #5  
Old April 25th, 2005, 06:20 PM
Peter Jamieson
external usenet poster
 
Posts: n/a
Default

Do You know, how to do this??

No, I haven't been able to find a way to use a table-valued function using
OLEDB. The only way I can get something similar to work is to use ODBC. For
example, if you have a user/system DSN called sql2000, in Word 2002/2003 the
following works here with suitable values for server, database and security
values:

OpenDataSource _
Name:="", _
Connection:="DSN=sql2000;SERVER=myserver;DATABASE= mydb;UID=myID;PWD=mypw;Trusted_Connection=No;",
_
SQLStatement:="SELECT * FROM myfunc(1)", _
Subtype:=wdMergeSubtypeWord2000

Or use

Connection:="DSN=sql2000;SERVER=myserver;DATABASE= mydb;Trusted_Connection=Yes;"

for a trusted connection.

I've tested the above. Experience suggests that if that works you can also
use a file dsn (which IMO is likely to be more easily distributed, like a
..odc) via

OpenDataSource _
Name:="pathname of the .dsn file", _
connection:="FILEDSN=pathnameof the .dsn file;additional parameters;", _
SQLStatement:="SELECT * FROM myfunc(1)"


Peter Jamieson

"Christof Nordiek" wrote in message
...
Hi Peter

OK, i now can use a statement with a where-clause for filtering. The next
thing i have to do is, call a table-valued function and give it an actual
value for a parameter.

SELECT * FROM MyFuction(58)

works from QueryAnalyzer and from .NET-application but not for Mail-Merge.
Do You know, how to do this??

Thanks

"Peter Jamieson" schrieb im Newsbeitrag
...
You can certainly pass an SQL SELECT statement with a WHERE clause.
Getting the syntax right can be difficult, as you have discovered. What I
find generally works is
a. quoting table and column names. I think it is clearer to use `` or []
rather than "" but it may be less standard these days
b. aliasing tables - even when aliasing should not be syntactiaclly
required - and always using the alias names when referencing individual
columns
c. using single quotes ' ' as text literal delimiters
e.g. (not tested - you'll need to play around to check)

SELECT [MV].* FROM [MyView] MV WHERE [MV].[MyColumn] = 'abc'

You may also be able to pass a call to a Transact-SQL procedure using the
old ODBC escape syntax which looks something like

{ call functionname(p1,p2) }

You may be able to find out more about that in SQL Server Books Online.
However, I have had a mixed experience using that approach in the past
because, for example, procedures that return multiple results do not seem
to work.

Peter Jamieson

"Christof Nordiek" wrote in message
...
i'm trying to make some MailMerge by automating word2003.
If i call MailMerge.OpenDataSource, what can i pass for the Satement
Parameter?
For Connectioninformation i'm using a *.odc file, wich connects to a
SQL-Server.
The name of the odc-file i pass as the Name parameter.

when I try
SELECT * FROM MyView
it fails.

SELECT * FROM "MyView"
succeeds.

Also passing the name of the view suceeds only with quotationmarks

What i'm trying to do is, passing a statement calling a table-valued
Function with parameters and/or a statement with a where clause
containing
Filterconditions.

Does anyone know, how to do this?

Thanks









  #6  
Old April 26th, 2005, 09:19 AM
Christof Nordiek
external usenet poster
 
Posts: n/a
Default

OK
i tried it with ODBC with dsn file. Looked good at first. But then i noticed
that all the textfields are empty.
When I try simple queries that work with odc file the result is the same:
textfields are empty.

"Peter Jamieson" schrieb im Newsbeitrag
...
Do You know, how to do this??


No, I haven't been able to find a way to use a table-valued function using
OLEDB. The only way I can get something similar to work is to use ODBC.
For example, if you have a user/system DSN called sql2000, in Word
2002/2003 the following works here with suitable values for server,
database and security values:

OpenDataSource _
Name:="", _

Connection:="DSN=sql2000;SERVER=myserver;DATABASE= mydb;UID=myID;PWD=mypw;Trusted_Connection=No;",
_
SQLStatement:="SELECT * FROM myfunc(1)", _
Subtype:=wdMergeSubtypeWord2000

Or use

Connection:="DSN=sql2000;SERVER=myserver;DATABASE= mydb;Trusted_Connection=Yes;"

for a trusted connection.

I've tested the above. Experience suggests that if that works you can also
use a file dsn (which IMO is likely to be more easily distributed, like a
.odc) via

OpenDataSource _
Name:="pathname of the .dsn file", _
connection:="FILEDSN=pathnameof the .dsn file;additional parameters;", _
SQLStatement:="SELECT * FROM myfunc(1)"


Peter Jamieson

"Christof Nordiek" wrote in message
...
Hi Peter

OK, i now can use a statement with a where-clause for filtering. The next
thing i have to do is, call a table-valued function and give it an actual
value for a parameter.

SELECT * FROM MyFuction(58)

works from QueryAnalyzer and from .NET-application but not for
Mail-Merge.
Do You know, how to do this??

Thanks

"Peter Jamieson" schrieb im Newsbeitrag
...
You can certainly pass an SQL SELECT statement with a WHERE clause.
Getting the syntax right can be difficult, as you have discovered. What
I find generally works is
a. quoting table and column names. I think it is clearer to use `` or []
rather than "" but it may be less standard these days
b. aliasing tables - even when aliasing should not be syntactiaclly
required - and always using the alias names when referencing individual
columns
c. using single quotes ' ' as text literal delimiters
e.g. (not tested - you'll need to play around to check)

SELECT [MV].* FROM [MyView] MV WHERE [MV].[MyColumn] = 'abc'

You may also be able to pass a call to a Transact-SQL procedure using
the old ODBC escape syntax which looks something like

{ call functionname(p1,p2) }

You may be able to find out more about that in SQL Server Books Online.
However, I have had a mixed experience using that approach in the past
because, for example, procedures that return multiple results do not
seem to work.

Peter Jamieson

"Christof Nordiek" wrote in message
...
i'm trying to make some MailMerge by automating word2003.
If i call MailMerge.OpenDataSource, what can i pass for the Satement
Parameter?
For Connectioninformation i'm using a *.odc file, wich connects to a
SQL-Server.
The name of the odc-file i pass as the Name parameter.

when I try
SELECT * FROM MyView
it fails.

SELECT * FROM "MyView"
succeeds.

Also passing the name of the view suceeds only with quotationmarks

What i'm trying to do is, passing a statement calling a table-valued
Function with parameters and/or a statement with a where clause
containing
Filterconditions.

Does anyone know, how to do this?

Thanks











  #7  
Old April 26th, 2005, 09:31 AM
Peter Jamieson
external usenet poster
 
Posts: n/a
Default

Another special Word "feature" :-(

If they are Unicode fields (NVARCHAR, NTEXT etc.) Word may not see the
contents (certainly with the ODBC route, but I thought it worked with
OLEDB). The best you can do in that case is use TransactSQL CAST/CONVERT to
return the VARCHAR, TEXT version. Unfortunately you may well be using
characters that are unavailable in the target character set.

Peter Jamieson
"Christof Nordiek" wrote in message
...
OK
i tried it with ODBC with dsn file. Looked good at first. But then i
noticed that all the textfields are empty.
When I try simple queries that work with odc file the result is the same:
textfields are empty.

"Peter Jamieson" schrieb im Newsbeitrag
...
Do You know, how to do this??


No, I haven't been able to find a way to use a table-valued function
using OLEDB. The only way I can get something similar to work is to use
ODBC. For example, if you have a user/system DSN called sql2000, in Word
2002/2003 the following works here with suitable values for server,
database and security values:

OpenDataSource _
Name:="", _

Connection:="DSN=sql2000;SERVER=myserver;DATABASE= mydb;UID=myID;PWD=mypw;Trusted_Connection=No;",
_
SQLStatement:="SELECT * FROM myfunc(1)", _
Subtype:=wdMergeSubtypeWord2000

Or use

Connection:="DSN=sql2000;SERVER=myserver;DATABASE= mydb;Trusted_Connection=Yes;"

for a trusted connection.

I've tested the above. Experience suggests that if that works you can
also use a file dsn (which IMO is likely to be more easily distributed,
like a .odc) via

OpenDataSource _
Name:="pathname of the .dsn file", _
connection:="FILEDSN=pathnameof the .dsn file;additional parameters;", _
SQLStatement:="SELECT * FROM myfunc(1)"


Peter Jamieson

"Christof Nordiek" wrote in message
...
Hi Peter

OK, i now can use a statement with a where-clause for filtering. The
next thing i have to do is, call a table-valued function and give it an
actual value for a parameter.

SELECT * FROM MyFuction(58)

works from QueryAnalyzer and from .NET-application but not for
Mail-Merge.
Do You know, how to do this??

Thanks

"Peter Jamieson" schrieb im Newsbeitrag
...
You can certainly pass an SQL SELECT statement with a WHERE clause.
Getting the syntax right can be difficult, as you have discovered. What
I find generally works is
a. quoting table and column names. I think it is clearer to use `` or
[] rather than "" but it may be less standard these days
b. aliasing tables - even when aliasing should not be syntactiaclly
required - and always using the alias names when referencing individual
columns
c. using single quotes ' ' as text literal delimiters
e.g. (not tested - you'll need to play around to check)

SELECT [MV].* FROM [MyView] MV WHERE [MV].[MyColumn] = 'abc'

You may also be able to pass a call to a Transact-SQL procedure using
the old ODBC escape syntax which looks something like

{ call functionname(p1,p2) }

You may be able to find out more about that in SQL Server Books Online.
However, I have had a mixed experience using that approach in the past
because, for example, procedures that return multiple results do not
seem to work.

Peter Jamieson

"Christof Nordiek" wrote in message
...
i'm trying to make some MailMerge by automating word2003.
If i call MailMerge.OpenDataSource, what can i pass for the Satement
Parameter?
For Connectioninformation i'm using a *.odc file, wich connects to a
SQL-Server.
The name of the odc-file i pass as the Name parameter.

when I try
SELECT * FROM MyView
it fails.

SELECT * FROM "MyView"
succeeds.

Also passing the name of the view suceeds only with quotationmarks

What i'm trying to do is, passing a statement calling a table-valued
Function with parameters and/or a statement with a where clause
containing
Filterconditions.

Does anyone know, how to do this?

Thanks













 




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Hyperlinks in Mail Merge IF...THEN...ELSE Statements Mark V Mailmerge 8 November 30th, 2004 01:31 PM
Select Query Parameter Repeating Neutron1871 Running & Setting Up Queries 1 October 8th, 2004 08:07 AM
How do I print the details view David Running & Setting Up Queries 5 August 28th, 2004 12:17 AM
Parameter Query with Parameter in If Statement Randal Running & Setting Up Queries 2 July 15th, 2004 09:39 PM
Access 2000 query SQL statement into VBA code Clint Running & Setting Up Queries 1 June 10th, 2004 01:33 PM


All times are GMT +1. The time now is 12:37 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.