在 bcp 实用程序中,导入/导出时,命令行将向我们显示复制的行数。 我尝试获取该号码以在其他处理中使用,但我不能。 命令行是:
bcp AdventureWorks2012.HumanResources.Department out D:\Department_Test.txt -S SERVER_NAME -T -c
结果:
Starting Copy...
16 rows copied.
....
请帮我获取复制的行数。
我尝试在命令行中使用FINDSTR来查找复制的行,它可以解决该问题,但我想找到更好的解决方案。
谢谢
最佳答案
这是一个黑客行为。
DECLARE @output TABLE (id INT IDENTITY, command NVARCHAR(256))
Declare @sql varchar(8000)='bcp AdventureWorks2012.HumanResources.Department out D:\Department_Test.txt -S SERVER_NAME -T -c'
INSERT INTO @output
exec master..xp_cmdshell @sql
SELECT cast(Replace(command,' rows copied.','') as int) FROM @output where command like '% rows copied.'
关于sql-server - BCP实用程序: How to get number of record imported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25781576/