views:

35

answers:

3

Hi guys,

Can I use TSQL to operate on normal operating system files? Such as create a .bat file at c:\test and write some query result into that batch file?

Thanks.

+1  A: 

Yes use SQLCMD

oluies
+1  A: 

For general tips on reading/writing files, you can check out this link.

You can also use SQLCMD, like this (input.sql would be your input sql, Results.txt would be your output):

SQLCMD -i Input.sql -o C:\Results.txt -e
dcp
+1  A: 

You could also use xp_cmdshell:

xp_cmdshell
Executes a given command string as an operating-system command shell and returns any output as rows of text. Grants nonadministrative users permissions to execute xp_cmdshell.

link to: xp_cmdshell - msdn reference

code4life