如何将字符串写入 ms sql 语句中的文本文件

Jol*_*ger -1 sql sql-server

我正在尝试将有关我的查询的一些日志数据写入文本文件。我从互联网上尝试了很多代码脚本,但没有奏效。如何将字符串写入文本文件?

我试过这个

我相信这在过去曾被问过几次,我看到了他们,但找不到正确的答案。谢谢

Suv*_*tha 7

尝试这个

首先创建存储过程而不是改变。请参阅下面的链接,该链接用于将字符串写入文件。

spWriteStringTofile

现在在执行之前,我们需要允许执行 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)

创建的文件截图 我希望这能帮到您。如果您有任何问题或建议,请告诉我。