Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2005, 04:56 AM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Interactively supplying inputs to SQL script

Hi,

Is there a way to send inputs to T-SQL scripts interactively from the command line ? For example, I have a script that takes a backup of the database. I wish to supply the inputs to it like the backup media, the database name etc from the command prompt interactively. How is this possible. Please help.

Thanks in Advance,
Vidya.

 
Old February 4th, 2005, 05:20 AM
Authorized User
 
Join Date: Jan 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OSQL is a command line utility, which u can use to manupolate the sql server.

Hope this will help u,

c:\ osql -S <Server Name> -U <User Name> -P <Password> -d <database Name>
-Q "execute sp_addumpdevice........... <T-SQL>"


Amit Jain
Sr. Software Engineer
 
Old February 4th, 2005, 05:23 AM
Authorized User
 
Join Date: Jan 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

vmaruv, instead of making two instences for a question, try resolve ur query in sinle instences.

let us explain so that we can provide the solution according to ur requirement.



Amit Jain
Sr. Software Engineer
 
Old February 4th, 2005, 05:41 AM
Authorized User
 
Join Date: Jan 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is my requirement in detail :

I have a T-SQL script that takes a database backup. This script can be run using osql as you suggested. But, the user is not willing to open the script and make changes to the the parameters like @databasename @device each time.

He wishes to interactively enter this from command prompt while running the script. Like : c:\ osql -U -P ...... test.sql It should prompt :

Enter database name : Northwind
Enter Device name : DISK

(these values should be assigned to @databsename and @Device in the scipt).

I would like to know how this is achievable.


Thanks in Advance.
Vidya



 
Old February 4th, 2005, 07:17 AM
Authorized User
 
Join Date: Jan 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

U have to create the batch file (.bat)

This batch file takes two parameter , by default its takes %1 and %2 as varibles.
Change the sql query according to your requirement.

here u have to take first parameter as database name and another as device name.

----------------------------------------------
@echo off

:: check first parameter is not null

IF %1=="" goto error1

:: check 2 parameter is not null

IF %2=="" goto error1


osql -S hondasrv -U std -P std -d pubs -Q "select * from %1"

exit

:error1
  echo "Please enter table name"


Amit Jain
Sr. Software Engineer





Similar Threads
Thread Thread Starter Forum Replies Last Post
How Run .sql Script file in MS SQL Server 2000? aarkaycee SQL Server 2000 5 October 12th, 2009 05:43 AM
Covering yourself legally when supplying software BananaJim Classic ASP Professional 1 March 12th, 2007 10:11 AM
1 form for multiple inputs Vince_421 Access VBA 2 February 6th, 2007 04:06 AM
interactively capture IE page nutrino VBScript 0 January 23rd, 2007 11:06 AM
FLASH User Inputs IP076 Flash (all versions) 1 January 5th, 2007 12:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.