是否可以使用选择或插入文件到服务器?如下所示,我在具有DBO特权的Windows计算机上使用SQL Server 2014。我不想使用clarify命令,是否可以选择或插入它来编写asp或aspx文件?
使用php,此代码可以正常运行SQL Server吗?
SELECT "some php code here"
INTO OUTFILE " /var/www/website/public_html/somefile.php"
答案 0 :(得分:0)
通过这种方式,您应该能够从Transact SQL代码中写入文本文件:
EXEC xp_cmdshell 'echo I want to write this text in a Text file from SSMS and programatically > c:\output.aspx'
请小心使用特殊字符。您需要通过在特殊字符之前插入^ char对它们进行换码。
否则,如果您的目标是将查询结果写入文本文件,那么我认为最好的方法是使用BCP命令。 (https://www.sqlshack.com/bcp-bulk-copy-program-command-in-action/)
例如:
EXEC master..xp_cmdshell 'BCP "SELECT * FROM MyTable" queryout "c:\output.csv" -w -t; -T -S MyServer'