Home All Groups Group Topic Archive Search About

Input File Variables

Author
17 Feb 2006 2:35 PM
mrprice
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

Author
17 Feb 2006 10:33 PM
Erland Sommarskog
mrprice (mrpr***@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, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
17 Feb 2006 11:01 PM
David Gugick
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
Author
17 Feb 2006 11:41 PM
mrprice
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

Show quote
"David Gugick" wrote:

> 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
>
>
Author
18 Feb 2006 12:31 AM
David Gugick
mrprice wrote:
Show quote
> 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:
>>> 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

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

AddThis Social Bookmark Button