如何从SQLCMD输出中删除空白

时间:2013-03-15 02:01:15

标签: windows sql-server-2008 for-loop batch-file cmd

我正在使用以下命令运行批处理文件,该命令基本上从sql表中提取数据。我的结果txt文件在结尾处给出一个空行。

SQLCMD.EXE -d FCRS_STG -i D:\export.sql -o E:\result.txt -s"," -W -h-1

export.sql是一个简单的选择查询

SET NOCOUNT ON
SELECT * from dbo.VW_FDM_SALES_ADJUST where app ='CN'

请帮我删除空白行。

谢谢, 拉维。

1 个答案:

答案 0 :(得分:1)

这将删除最后一行:

@echo off &setlocal
for /f "tokens=1*delims=:" %%i in ('findstr /n "^" result.txt') do set /a count=%%i
for /f "tokens=1*delims=:" %%i in ('findstr /n "^" result.txt') do if %%i lss %count% >>newfile.txt echo.%%j
endlocal
相关问题