|
Home > Archive > MS SQL Server Tools > February 2006 > Input File Variables
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Input File Variables
|
|
| mrprice 2006-02-17, 9:23 am |
| I am using an input file with osql to run a rather lengthy script (osql -n
–iLoad_It.sql). Is there any way to pass command line variables into the
Load_It.sql script?
Thanks,
Mark
| |
| Erland Sommarskog 2006-02-17, 8:24 pm |
| mrprice (mrprice@discussions
.microsoft.com) writes:
> I am using an input file with osql to run a rather lengthy script (osql -n
> -iLoad_It.sql). Is there any way to pass command line variables into the
> Load_It.sql script?
Not more than would do through variable expansion in DOS.
If you are on SQL 2005, look into SQLCMD instead; it has some functionality
for this.
If you are on SQL 2000, consider embedding the SQL in VBscript, Perl or
similar.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx
| |
| David Gugick 2006-02-17, 8:24 pm |
| mrprice wrote:
> I am using an input file with osql to run a rather lengthy script
> (osql -n –iLoad_It.sql). Is there any way to pass command line
> variables into the Load_It.sql script?
>
> Thanks,
> Mark
You could do this through the -H Workstation parameter if you needed to.
THat parameter can be defined as you like and can be accessed from T-SQL
using the HOST_NAME() function. For example, you can run the following
from QA:
Exec master..xp_cmdshell N'osql -e -E -h-1 -H"998-72-3567" -dpubs -q"SET
NOCOUNT ON;DECLARE @au_id id SET @au_id = HOST_NAME() Select au_id from
dbo.authors Where au_id = @au_id'
--
David Gugick - SQL Server MVP
Quest Software
| |
| mrprice 2006-02-17, 8:24 pm |
| David,
And I suppose if I had multiple variables I wanted to pull in, I could parse
it (HOST_NAME()) once I have it inside the sql script?
Thanks,
Mark
"David Gugick" wrote:
> mrprice wrote:
>
> You could do this through the -H Workstation parameter if you needed to.
> THat parameter can be defined as you like and can be accessed from T-SQL
> using the HOST_NAME() function. For example, you can run the following
> from QA:
>
> Exec master..xp_cmdshell N'osql -e -E -h-1 -H"998-72-3567" -dpubs -q"SET
> NOCOUNT ON;DECLARE @au_id id SET @au_id = HOST_NAME() Select au_id from
> dbo.authors Where au_id = @au_id'
>
>
> --
> David Gugick - SQL Server MVP
> Quest Software
>
>
| |
| David Gugick 2006-02-17, 8:24 pm |
| mrprice wrote:[color=darkred
]
> David,
>
> And I suppose if I had multiple variables I wanted to pull in, I
> could parse it (HOST_NAME()) once I have it inside the sql script?
>
> Thanks,
> Mark
>
> "David Gugick" wrote:
>
You could do that as well. It's a bit of a kludge, but it will work - at
least until you find a better solution.
--
David Gugick - SQL Server MVP
Quest Software
|
|
|
|
|