Tuesday, March 20, 2012

Calling another .sql file from an existing .sql file

I have a vb application that executes a .sql file called "fileA.sql" using
the osql cmd.
I would like to know how to make fileA.sql call fileB.sql.
In an oracle based .sql file, I generally would call fileB.sql from within
fileA.sql using
the following script
@.@.fileB.sql
This does not seem to work against sql server.
Thanks.
--
ANeelimaHi
File calls another file? I'm not aware of such issue?
However , you can call the file to do some operations as
UPDATE/INSERT/DELETE/SELECT and then make some logic here.
D you mean that fileA does not contain any info about fileB?
"ANeelima" <neelima@.newsgroups.nospam> wrote in message
news:E96C2EE7-7383-47F7-A7B8-801FBE9541E6@.microsoft.com...
>I have a vb application that executes a .sql file called "fileA.sql" using
> the osql cmd.
> I would like to know how to make fileA.sql call fileB.sql.
> In an oracle based .sql file, I generally would call fileB.sql from within
> fileA.sql using
> the following script
> @.@.fileB.sql
> This does not seem to work against sql server.
> Thanks.
> --
> ANeelima|||Yes, the intention is for FileA.sql to call FileB.sql. Instead of calling
all the files individually from my VB application I wanted to call one singl
e
file called FileA.sql
and have FileA.sql call FileB.sql, FileC.sql, and so on.
I can do that when executing sql files against Oracle without any problems.
So, if it were Oracle, the script in FileA.sql will be
----
set verify off;
set echo off;
@.@.FileB.ql;
PAUSE;
@.@.FileC.sql;
EXIT;
----
If I use the same script against SQL Server I get the error saying that
@.@.FileB.sql is not recognized.
ANeelima
"Uri Dimant" wrote:

> Hi
> File calls another file? I'm not aware of such issue?
> However , you can call the file to do some operations as
> UPDATE/INSERT/DELETE/SELECT and then make some logic here.
> D you mean that fileA does not contain any info about fileB?
>
>
> "ANeelima" <neelima@.newsgroups.nospam> wrote in message
> news:E96C2EE7-7383-47F7-A7B8-801FBE9541E6@.microsoft.com...
>
>|||In file A, use OSQL (again) to call file B.
Arnie Rowland*
"To be successful, your heart must accompany your knowledge."
"ANeelima" <neelima@.newsgroups.nospam> wrote in message
news:E96C2EE7-7383-47F7-A7B8-801FBE9541E6@.microsoft.com...
>I have a vb application that executes a .sql file called "fileA.sql" using
> the osql cmd.
> I would like to know how to make fileA.sql call fileB.sql.
> In an oracle based .sql file, I generally would call fileB.sql from within
> fileA.sql using
> the following script
> @.@.fileB.sql
> This does not seem to work against sql server.
> Thanks.
> --
> ANeelima|||"ANeelima" <neelima@.newsgroups.nospam> wrote in message
news:E96C2EE7-7383-47F7-A7B8-801FBE9541E6@.microsoft.com...
>I have a vb application that executes a .sql file called "fileA.sql" using
> the osql cmd.
> I would like to know how to make fileA.sql call fileB.sql.
> In an oracle based .sql file, I generally would call fileB.sql from within
> fileA.sql using
> the following script
> @.@.fileB.sql
> This does not seem to work against sql server.
...
To my knowledge there isn't a "built in" preprocessor as you describe.
Generally people use stored procedures instead of file level modules. I
have heard of people using a C language preprocessor with regard to
configuration management with few difficulties.
B|||In order to use osql to call file B from file A, I would have to hard-code
the database and server name in File A as in
osql -E -n -S %COMPUTERNAME%\MYINSTANCE -dENDESKTOP11 -i "FileB.sql" -o
"FileB.log"
But, my goal is to not hard-code the database nor the instance/server name
in FileA.sql since the user chooses the database and server name at run-time
from the VB application.
The VB application then uses the selected names and executes a osql command
and runs FileA.sql using the shell cmd programmatically. Thus I was hoping
that there was a way to simply set the database and server in FileA.sql
(which is the parent sql file) and have FileA call FileB, FileC, etc.
Based on the responses, it appears like I cannot do that as in Oracle.
--
ANeelima
"Arnie Rowland" wrote:

> In file A, use OSQL (again) to call file B.
> --
> Arnie Rowland*
> "To be successful, your heart must accompany your knowledge."
>
> "ANeelima" <neelima@.newsgroups.nospam> wrote in message
> news:E96C2EE7-7383-47F7-A7B8-801FBE9541E6@.microsoft.com...
>
>|||Hi, ANeelima,
Thanks for your post.
From your description, I understand that:
Your VB application used osql command to execute SQL script files. In your
case, you wanted one sql file can invoke another sql file avoiding hard
code of osql in it.
If I have misunderstood, please let me know.
I don't find other commands or functions can invoke other sql files without
login, which may be different from Oracle.
However, in my experiences, such expression @.@.fileb.sql is supported by
SQL*Plus, while it is not supported by OSQL.
You can only pass the sql file name as -i parameter of osql command.
If you want to just connect your database server only once, I recommend you
use ADO or ODBC to connect the server and the read and execute the sql
files line by line.
Also, if you don't care about the connection times of osql, you may create
a .bat file with osql command and the execute the .bat file only once.
Also, for such feature request, you may click the link below and give
Microsoft feedback for product improvement. Your suggestions are most
valuable to Microsoft.
http://lab.msdn.microsoft.com/produ...ck/default.aspx
If you have any other concerns, please feel free to let me know. It's my
pleasure to be of assistance.
+++++++++++++++++++++++++++
Charles Wang
Microsoft Online Partner Support
+++++++++++++++++++++++++++
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
========================================
=============
Business-Critical Phone Support (BCPS) provides you with technical phone
support at no charge during critical LAN outages or "business down"
situations. This benefit is available 24 hours a day, 7 days a week to all
Microsoft technology partners in the United States and Canada.
This and other support options are available here:
BCPS:
https://partner.microsoft.com/US/te...erview/40010469
Others:
https://partner.microsoft.com/US/te...upportoverview/
If you are outside the United States, please visit our International
Support page:
http://support.microsoft.com/defaul...rnational.aspx.
========================================
=============
This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi,
I am interested in this issue. Would you mind letting me know the result of
the suggestions? If you need further assistance, feel free to let me know.
I will be more than happy to be of assistance.
Have a great day!
Charles Wang[MSFT]
Microsoft Developer Online Support

No comments:

Post a Comment