如何在 SQLCMD 中使用 TAB 作为列分隔符 [英] How to use TAB as column separator in SQLCMD

查看:52
本文介绍了如何在 SQLCMD 中使用 TAB 作为列分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQLCMD 支持 -s 参数来指定列分隔符,但我无法弄清楚如何表示制表符 (CHAR(9)) 字符.我尝试了以下方法,但都不起作用:

SQLCMD supports the -s parameter to specify the column separator, but I couldn't figure how how to represent the tab (CHAR(9)) character. I have tried the following but both don't work:

sqlcmd -S ServerName -E -Q"select * from mytable" -s"\t" -o results.txt
sqlcmd -S ServerName -E -Q"select * from mytable" -s'\t' -o results.txt

任何想法如何在 SQLCMD 中做到这一点?

Any ideas how to do this in SQLCMD?

推荐答案

在批处理文件中,在双引号之间放置制表符是有效的.

In a batch file, putting a tab between the double quotes works.

sqlcmd -S ServerName -E -Q"select * from mytable" -s"   " -o results.txt

要在 PowerShell 文件中执行相同操作,请使用环绕转义选项卡的转义双引号

to do the same in a PowerShell file use escaped double quotes wrapped around an escaped tab

sqlcmd -S ServerName -E -Q"select * from mytable" -s `"`t`" -o results.txt

这篇关于如何在 SQLCMD 中使用 TAB 作为列分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆