[英]Export @tempTable to .txt file in SQL server
Check my last question Export values from SQL Server to txt file . 检查我的最后一个问题: 将值从SQL Server导出到txt文件 。 I can able to export values to .txt file with my last question.
我可以将最后一个问题导出到.txt文件中。 I want to do export
@tempTable
to .txt file. 我想将
@tempTable
导出到.txt文件。 How can I do this? 我怎样才能做到这一点?
Edit: My Requirement: I want to export only updated data from a table to .txt file, say user insert 10 new rows of data in existing table, I want that 10 rows to be there in .txt file. 编辑:我的要求:我只想将表中的更新数据导出到.txt文件,比如说用户在现有表中插入10行新数据,我希望那10行在.txt文件中。 I used Inserted table in trigger to get updated rows, when I try to export to .txt file from
bcp
, I can't since I don't know the full context of inserted table([database].[schema].[tableName]). 当我尝试从
bcp
导出到.txt文件时,我在触发器中使用了插入表来获取更新的行,因为我不知道插入表的完整上下文([数据库]。[模式]。[tableName] ])。 So I decided to have inserted table data in @tempTable
to export .txt file. 因此,我决定在
@tempTable
插入表数据以导出.txt文件。
This is I suppose to do export inserted table data to .txt file in SQL server . 我想这是将插入的表数据导出到SQL Server中的.txt文件 。
you could simply load the memory table into a regular table an then use your code for export that you already have 您可以简单地将内存表加载到常规表中,然后使用您已有的代码进行导出
select * into queryout from @tempTable
-- your code from step 1
drop table queryout
here is an updated version of your trigger which should do the work 这是您应该执行的触发器的更新版本
create trigger monitorTest1 on test for insert as
declare @sql varchar(8000);
select * into tempTable from inserted
SELECT @sql = 'bcp "select * from test2.dbo.tempTable" queryout C:\temp\mytest.txt -c -t -T -S localhost'
exec xp_cmdshell @sql
drop table tempTable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.