我正在尝试将有关我的查询的一些日志数据写入文本文件。我从互联网上尝试了很多代码脚本,但没有奏效。如何将字符串写入文本文件?
我试过这个。
我相信这在过去曾被问过几次,我看到了他们,但找不到正确的答案。谢谢
尝试这个
首先创建存储过程而不是改变。请参阅下面的链接,该链接用于将字符串写入文件。
现在在执行之前,我们需要允许执行 Ole 自动化程序的权限。为此,请复制以下代码并执行。
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ole Automation Procedures', 1;
GO
RECONFIGURE;
GO
Run Code Online (Sandbox Code Playgroud)
最后执行以下代码将字符串存储到文件。
execute spWriteStringToFile 'This article describes how to fully access the
local filesystem from SQL Server. It shows a
way of reading and writing data to file, and
accessing the details of the server''s
filesystem using OLE Automation to access
the filesystem object'
, 'D:\Demo','test.txt';
Run Code Online (Sandbox Code Playgroud)