May 27, 2010 at 2:21 am
Hi,
I need to use xp_cmdshell to execute a stored procedure that is my c:
The name of the stored procedure is Script22.sql
I have seen the following example on the internet:
exec master.dbo.xp_cmdshell 'osql -E -Sserver1 -i c:\tempightly.sql'
But i think that in SQL Server 2005 the OSQL was replace by CMDSQL, am i correct?
How can i alter this command so that it runs the script in cmdSQL and if the script raises any error, i can catch it?
Thank you
July 28, 2010 at 12:48 pm
July 29, 2010 at 9:00 am
Havent tried it but would assume that you would pipe to an output file. something like:
sqlcmd -S . -d master -Q "select name from sys.databases" -o "c:\output.csv"
But obviously inside a XP_cmd... statement.
Hope this helps. 🙂
Adam Zacks-------------------------------------------Be Nice, Or Leave
July 29, 2010 at 9:10 am
Schadenfreude-Mei (7/29/2010)
Havent tried it but would assume that you would pipe to an output file. something like:sqlcmd -S . -d master -Q "select name from sys.databases" -o "c:\output.csv"
But obviously inside a XP_cmd... statement.
Hope this helps. 🙂
SO in your case:
EXEC xp_cmdshell 'sqlcmd -S . -d master -i "c:\sqlscript.sql" -o "c:\output.csv"'
Or something like that. Simples (squeeky meercat noise!)
Adam Zacks-------------------------------------------Be Nice, Or Leave
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply