8

This works but not in utf-8:

sqlcmd -S Server -d DB -E -s, -W -i "C:\Localdata\test.sql" | findstr /V /C:"-" /B > "C:\Localdata\Test.csv"

Would anybody like to help fix this into utf-8?

JoezCodes
  • 157
  • 2
  • 15

4 Answers4

12

add -f 65001 to the sqlcmd command. (or -f o:65001 if you want UTF-8 output, -f i:65001 for UTF-8 input)

denbrice
  • 121
  • 1
  • 2
6

You can use the -u switch for Unicode format output file.

Docs

shree.pat18
  • 21,449
  • 3
  • 43
  • 63
2

type chcp 65001 in the command line or batch file before calling sqlcmd

robotik
  • 1,837
  • 1
  • 20
  • 26
0

But it's not UTF-8.

sqlcmd automatically recognizes both big-endian and little-endian Unicode input files. If the -u option has been specified, the output will always be little-endian Unicode.

And thus, for instance, it disables using diff tool to compare output.

To overcome this M$ "comfort" with tool - use iconv:

iconv -t UTF-8 <sqlcmd.output.csv>

At Windows as "comfortable" М$ product again - you can use iconv from Git command line tool bundle, for instance.

mdn
  • 363
  • 3
  • 10