Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've tried numerous times to pass the actual TAB character in to SQLCMD, and I simply can't get it to take it. My favorite work-around to-date is to pass SQLCMD the ASCII "Unit Separator", which is hex 0x1F, and can be entered on the command line by typing Ctrl-_ (control underscore, which on a US keyboard becomes ctrl-shift-'-' (the '-' next to the '0' on the top row of the keyboard).</p> <p>The advantage of using the 'Unit Separator' is that is is HIGHLY unlikely to be present in text of any description, and was designed specifically for this purpose (see <a href="https://en.wikipedia.org/wiki/Delimiter" rel="nofollow">https://en.wikipedia.org/wiki/Delimiter</a>)</p> <p>Having got SQLCMD to do that for me, I then pipe it's output though a Unix-style translate command as:</p> <pre><code>tr '\037' '\t' </code></pre> <p>The \037 is octal for the 'Unit Separator', and \t represents the tab character, 'tr' will translate BOTH of these for us, we don't need to rely on any quoting tricks in our scripts or shells.</p> <p>To get 'tr' on windows, you can install the CoreUtils package from GnuWin32 (see <a href="http://gnuwin32.sourceforge.net/packages/coreutils.htm" rel="nofollow">http://gnuwin32.sourceforge.net/packages/coreutils.htm</a>) or go heavy-weight and install a full Unix environment such as Cygwin (http://cygwin.com/).</p> <p>Putting the two together we get:</p> <pre><code>sqlcmd ... -h-1 -W -k -r1 -s^_ ... | tr '\037' '\t' </code></pre> <p>and this will give you your output with tabs.</p> <p>Look up the other options I've used above, they're essential for trying to get clean output from SQLCMD (in order; no headers, trim white-space, CRLF to spaces, errors to STDERR (not your output file!) and the '^_' is how the Unit Separator will appear on the command line). You'll also need to add "SET NOCOUNT ON;" to your query or sql script, otherwise you'll get the row-count as a trialling message appearing in your output!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload