February 3, 2016 at 11:43 pm
Can someone please provide a script\storedprocedure to perform below steps.
1.connect to sql instance
2.Run a sql file(C:\abc.sql)
3.Store result in a file(C:\abc.txt)
thanks
February 4, 2016 at 8:17 am
sqlcmd -S servername -E -d Databasename -i c:\abc.sql -o c:\abc.txt
February 4, 2016 at 6:53 pm
Steve Jones - SSC Editor (2/4/2016)
sqlcmd -S servername -E -d Databasename -i c:\abc.sql -o c:\abc.txt
You can also substitute a ">" for the "-o". It will cause the file to be overwritten if it already exists. Substituting ">>" will cause the file to be appended with the new information.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 5, 2016 at 2:53 pm
Yep, Jeff is right that you can use redirection from a command line.
If you need to do this inside SQL Server, you can use xp_cmdshell to call this in a shell.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply