如何在T-SQL中使用存储过程创建文件

时间:2023-01-11 23:54:05

i am trying to create a file with a stored procedure in T-SQL. I need this to trigger an event in another program. Could anybody help me with that? I didn't find much on google that really helped me. I would like to have an empty file named "newWCC.dd". Path doesn't matter yet because I just want to know how I even create it

我试图在T-SQL中创建一个带有存储过程的文件。我需要这个来触发另一个程序中的事件。有人可以帮我吗?我在google上找不到真正帮助我的东西。我想有一个名为“newWCC.dd”的空文件。路径并不重要,因为我只是想知道我是如何创建它的

1 个解决方案

#1


2  

You can create text files from SQL Server using BCP utility as follows

您可以使用BCP实用程序从SQL Server创建文本文件,如下所示

declare @cmd varchar(1000)
declare @filepath varchar(500) = 'c:\temp\samplefile.dd'
SET @cmd = 'bcp "select 1 as test" queryout "' + @filepath + '" -c -UTF8 -T -Slocalhost'
EXEC master..xp_cmdshell @cmd

We can even remove the SELECT part from @cmd

我们甚至可以从@cmd中删除SELECT部分

declare @cmd varchar(1000)
declare @filepath varchar(500) = 'c:\temp\samplefile.dd'
SET @cmd = 'bcp "" queryout "' + @filepath + '" -c -UTF8 -T -Slocalhost'
EXEC master..xp_cmdshell @cmd

You can check for a more complex usage on SQL tutorial SQL Server BCP Utility to generate script file for stored procedures

您可以在SQL教程SQL Server BCP实用程序上检查更复杂的用法,以生成存储过程的脚本文件

I hope it helps

我希望它有所帮助

#1


2  

You can create text files from SQL Server using BCP utility as follows

您可以使用BCP实用程序从SQL Server创建文本文件,如下所示

declare @cmd varchar(1000)
declare @filepath varchar(500) = 'c:\temp\samplefile.dd'
SET @cmd = 'bcp "select 1 as test" queryout "' + @filepath + '" -c -UTF8 -T -Slocalhost'
EXEC master..xp_cmdshell @cmd

We can even remove the SELECT part from @cmd

我们甚至可以从@cmd中删除SELECT部分

declare @cmd varchar(1000)
declare @filepath varchar(500) = 'c:\temp\samplefile.dd'
SET @cmd = 'bcp "" queryout "' + @filepath + '" -c -UTF8 -T -Slocalhost'
EXEC master..xp_cmdshell @cmd

You can check for a more complex usage on SQL tutorial SQL Server BCP Utility to generate script file for stored procedures

您可以在SQL教程SQL Server BCP实用程序上检查更复杂的用法,以生成存储过程的脚本文件

I hope it helps

我希望它有所帮助