Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Passing variable into OSQL

Author  Topic 

Johnho008
Starting Member

24 Posts

Posted - 2008-05-29 : 05:40:34
Hi,

Just wanted to know if you can pass variable into OSQL command.i.e

OSQL -E -S{Servernam} -d{database} -q "select * from table where userid = @userid"

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-29 : 13:06:01
You can via DOS code, so you'd have to wrap your osql call into a batch files. I believe you use % to indicate variables there. You'll need to do some research on the DOS code though as I'm a bit rusty.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-05-29 : 15:20:22
set USERID=34234234
OSQL -E -S{Servernam} -d{database} -q "select * from table where userid = %USERID%"


elsasoft.org
Go to Top of Page

Johnho008
Starting Member

24 Posts

Posted - 2008-05-30 : 05:14:51
Thanks everyone,

I ended up using SQLCMD command instead

SET /P UserName="Enter UserName"
SET /P Costcentre="Enter Costcentre"

sqlcmd -S{servername} -vUserName="%UserName%" -vCostcentre="%Costcentre%" -i {Input TSQL file}

Worked like a dream allowing user input
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-05-30 : 10:13:00
i would have suggested using sqlcmd but you posted in the 2000 forum, so I assumed you didn't have sqlcmd available to you.


elsasoft.org
Go to Top of Page
   

- Advertisement -