[英]SQL Server 2014 command writing file to server?
Is it possible to use either select or insert into a file to server? 是否可以使用select或insert到文件到服务器? Such as this below I am using SQL Server 2014 on a Windows machine with DBO privileges. 如下所示我在具有DBO权限的Windows机器上使用SQL Server 2014。 I don't want to use declare command is it possible to do it select or insert into to write asp or aspx file ? 我不想使用declare命令是否可以选择或插入来编写asp或aspx文件?
With php this code is working how about SQL Server? 用php这个代码正在研究SQL Server怎么样?
SELECT "some php code here"
INTO OUTFILE " /var/www/website/public_html/somefile.php"
By this way you should be able to write in a text file from Transact SQL code: 通过这种方式,您应该能够从Transact SQL代码中写入文本文件:
EXEC xp_cmdshell 'echo I want to write this text in a Text file from SSMS and programatically > c:\output.aspx'
Be carefull with the special chars. 小心特殊的字符。 You will need to scape them by inserting the ^ char just before the special char. 您需要在特殊字符之前插入^ char来进行scape。
Otherwise, if your goal is to write the query results to a text file, the best way to do it, in my opinion, would be by using BCP command. 否则,如果您的目标是将查询结果写入文本文件,那么在我看来,最好的方法是使用BCP命令。 ( https://www.sqlshack.com/bcp-bulk-copy-program-command-in-action/ ) ( https://www.sqlshack.com/bcp-bulk-copy-program-command-in-action/ )
For example: 例如:
EXEC master..xp_cmdshell 'BCP "SELECT * FROM MyTable" queryout "c:\output.csv" -w -t; -T -S MyServer'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.