October 21, 2002 at 10:52 pm
I'm new to SQL and would like to create a text file from a sql query. I understand that xp_cmdshell could be used:
exec master..xp_cmdshell 'osql -Q "select batnbr from xtemptable" -O"c:\test.txt"'
Unfortunately, I get the error msg:
Password:
Msg 208, Level 16, State 1:
[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name
'xtemptable'.
(4 row(s) affected)
The xtemptable is located at a different db and not in the master one. I even tried exec master..xpcmdshell. Appreicate any help.
October 22, 2002 at 2:11 am
duplicate see
Simon Sabin
Co-author of SQL Server 2000 XML Distilled
http://www.amazon.co.uk/exec/obidos/ASIN/1904347088
Simon Sabin
SQL Server MVP
http://sqlblogcasts.com/blogs/simons
October 22, 2002 at 5:16 pm
Check that osql -d is used to specify the database, maybe when you execute the cmdshell, osql stands on master database. If so, specify the db with the -d option, or in the select statement include the db. For example:
exec master..xp_cmdshell 'osql -Q "select batnbr from dbname.dbo.xtemptable" -O"c:\test.txt"'
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply