|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Input File VariablesI 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 mrprice (mrpr***@discussions.microsoft.com) writes:
> I am using an input file with osql to run a rather lengthy script (osql -n Not more than would do through variable expansion in DOS.> -iLoad_It.sql). Is there any way to pass command line variables into the > Load_It.sql script? 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 mrprice wrote:
> I am using an input file with osql to run a rather lengthy script You could do this through the -H Workstation parameter if you needed to. > (osql -n –iLoad_It.sql). Is there any way to pass command line > variables into the Load_It.sql script? > > Thanks, > Mark 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,
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 > > mrprice wrote:
Show quote > David, You could do that as well. It's a bit of a kludge, but it will work - at > > 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 least until you find a better solution. -- David Gugick - SQL Server MVP Quest Software |
|||||||||||||||||||||||