<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Export pipe delimited data in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825160#M4856003</link>
    <description>&lt;P&gt;See my other answer: It's no OUTPUT or dbisql problem, it's just the fact that you use the unmasked pipe in a command line where it has a particular meaning (i.e. to create a pipeline between two programs) and has to be escaped here if that meaning is not desired.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Feb 2016 03:49:02 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2016-02-22T03:49:02Z</dc:date>
    <item>
      <title>Export pipe delimited data</title>
      <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaq-p/13825153</link>
      <description>&lt;P&gt;I have been exporting data as a csv file using xp_cmdshell within a stored procedure successfully for some time now in Sybase ASA 12.&lt;/P&gt;
&lt;P&gt;I wish to export similar data, but pipe delimited instead of comma separated values.&lt;/P&gt;
&lt;P&gt;From within ISQL the following works pefectly:&lt;/P&gt;
&lt;LI-CODE lang="sql"&gt;select '0300' AS HospitalCode, TRIM(URNumber), OrderType, SentenceType, OriginalDateStart,VariationNo, SentenceMonths,DateStart, DateExpiry, CLCAct, LifeIndicator, GPIndicator,TRIM(fnCurrentLocation(CMHO.URNumber)) as CurrentLocation, W.Ward from ClientMHAOrders as CMHO left outer JOIN Wards as W on W.WardName = CurrentLocation WHERE OrderType = 'FP' ORDER BY CMHO.URNumber, CMHO.DateStart; OUTPUT TO 'c:\\\\temp\\\\GLN_FORENSIC_20160220.txt' FORMAT TEXT DELIMITED BY '|' WITH COLUMN NAMES; 2&amp;gt; 'C:\\\\temp\\\\ForensicData.log','no_output'&lt;/LI-CODE&gt;


&lt;P&gt;Now when I put the code into a stored procedure as this:&lt;/P&gt;
&lt;LI-CODE lang="sql"&gt;call xp_cmdshell('""%SQLANY12%\\\\Bin32\\\\dbisql" -q -c "UID=DBA;PWD=sql;Server=MyServer;Database=TestData" SELECT ''0300'' AS HospitalCode, TRIM(URNumber), OrderType, SentenceType, OriginalDateStart, VariationNo, SentenceMonths, DateStart, DateExpiry, CLCAct, LifeIndicator, GPIndicator, TRIM(fnCurrentLocation(CMHO.URNumber)) as CurrentLocation, W.Ward from ClientMHAOrders as CMHO left outer JOIN Wards as W on W.WardName = CurrentLocation WHERE OrderType = ''FP'' ORDER BY CMHO.URNumber, CMHO.DateStart; OUTPUT TO ''c:\\\\temp\\\\GLN_FORENSIC_20160220.txt'' FORMAT TEXT DELIMITED BY ''|'' WITH COLUMN NAMES; 2&amp;gt; C:\\\\temp\\\\ForensicData.log"','no_output')&lt;/LI-CODE&gt;


&lt;P&gt;My stored procedure creates an error entry within the log file:
''' is not recognized as an internal or external command, operable program or batch file.&lt;/P&gt;
&lt;P&gt;If I remove the "DELIMITED BY ''|'' it works, but the output is comma delimited. Obviously I have an error in syntax possibly, can anyone help with this please.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Feb 2016 22:32:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaq-p/13825153</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2016-02-19T22:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Export pipe delimited data</title>
      <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825156#M4855999</link>
      <description>&lt;P&gt;Try representing the pipe character as an escaped hex character '\\xZZ' where ZZ is the hex for pipe.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 09:28:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825156#M4855999</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2016-02-20T09:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Export pipe delimited data</title>
      <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825157#M4856000</link>
      <description>&lt;P&gt;HI Breck.&lt;/P&gt;
&lt;P&gt;No that didn't work, now I do get the file created, but \\xZZ becomes the delimiter, not the hex equivalent. Oh isn't 7C the hex equivalant of the vertical bar "pipe" ?. I tried that too.
Interestingly if I use the "^" character it works, just not "|".&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 18:27:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825157#M4856000</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2016-02-20T18:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: Export pipe delimited data</title>
      <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825158#M4856001</link>
      <description>&lt;P&gt;I have tried this too which works for the HEx character broken pipe,&lt;/P&gt;
&lt;P&gt;FORMAT TEXT DELIMITED BY ''\\xA6'' ESCAPES ON WITH .....&lt;/P&gt;
&lt;P&gt;Each time I try to represent the pipe character ''\\x7C'' I get the same error in the log file.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 18:48:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825158#M4856001</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2016-02-20T18:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Export pipe delimited data</title>
      <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825154#M4855997</link>
      <description>&lt;P&gt;Have you tried to use the &lt;A href="http://dcx.sap.com/index.html#1201/en/dbreference/unload-statement.html"&gt;UNLOAD statement&lt;/A&gt; instead of the "xp_cmdshell/OUTPUT TO" approach? - AFAIK, you would have to use an initial UNLOAD to add the column headers and then use UNLOAD ... APPEND or use an UNION to add column headers. (v17 has added a helpful WITH COLUMNS NAMES clause...)&lt;/P&gt;
&lt;P&gt;Note, I have not tried to use a pipe character with UNLOAD but I guess the syntax is easier to use from within a stored procedure than your current approach.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 19:41:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825154#M4855997</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2016-02-20T19:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: Export pipe delimited data</title>
      <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825159#M4856002</link>
      <description>&lt;P&gt;Hi Volker,&lt;/P&gt;
&lt;P&gt;The UNLOAD statement worked. Thanks.
For information it would be interesting to know why the pipe character is the only character that doesn't work in the OUTPUT statement.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Feb 2016 23:17:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825159#M4856002</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2016-02-20T23:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Export pipe delimited data</title>
      <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825155#M4855998</link>
      <description>&lt;P&gt;While I highly recommend to use UNLOAD instead of a cmd shell and a DBISQL session to output data from a stored procedure, I guess the following should do the trick:&lt;/P&gt;
&lt;P&gt;In your original statement the '|' seems to be interpreted as a command line operator, whether it is used within quotes or not. (Note: That's my humble impression, I'm not command line expert at all...). Here's an attempt for a similar query run against the v12 demo database, directly on the command line (and therefore without doubled quotes and the like...)&lt;/P&gt;
&lt;PRE&gt;"%SQLANY12%\\Bin64\\dbisql" -q -c "UID=DBA;PWD=sql;DSN=SQL Anywhere
 12 Demo" select * from sysusertype order by type_name; OUTPUT TO 'c:\\PipeDelim
itedExport.txt' FORMAT TEXT DELIMITED BY '|' WITH COLUMN NAMES; 2&amp;gt; C:\\PipeDelim
itedExportError.log
&lt;/PRE&gt;

&lt;P&gt;This raises the same error you mentioned.&lt;/P&gt;
&lt;P&gt;However, if you put the whole SQL statement within a double quote, the export works just fine in my tests with 12.0.1.4314 - and I would think it is because that way the command shell does not try to interpret the pipe character itself:&lt;/P&gt;
&lt;PRE&gt;"%SQLANY12%\\Bin64\\dbisql" -q -c "UID=DBA;PWD=sql;DSN=SQL Anywhere
 12 Demo" "select * from sysusertype order by type_name; OUTPUT TO 'c:\\PipeDelim
itedExport.txt' FORMAT TEXT DELIMITED BY '|' WITH COLUMN NAMES;" 2&amp;gt; C:\\PipeDelim
itedExportError.log
&lt;/PRE&gt;

&lt;P&gt;Or, alternatively, you can &lt;A href="http://stackoverflow.com/questions/1200235/how-to-pass-a-quoted-pipe-character-to-cmd-exe"&gt;escape the pipe character on the command shell with a leading caret&lt;/A&gt;:&lt;/P&gt;
&lt;PRE&gt;"%SQLANY12%\\Bin64\\dbisql" -q -c "UID=DBA;PWD=sql;DSN=SQL Anywhere
 12 Demo" select * from sysusertype order by type_name; OUTPUT TO 'c:\\PipeDelim
itedExport.txt' FORMAT TEXT DELIMITED BY '^|' WITH COLUMN NAMES; 2&amp;gt; C:\\PipeDelim
itedExportError.log
&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Feb 2016 03:40:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825155#M4855998</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2016-02-22T03:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Export pipe delimited data</title>
      <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825160#M4856003</link>
      <description>&lt;P&gt;See my other answer: It's no OUTPUT or dbisql problem, it's just the fact that you use the unmasked pipe in a command line where it has a particular meaning (i.e. to create a pipeline between two programs) and has to be escaped here if that meaning is not desired.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 03:49:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825160#M4856003</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2016-02-22T03:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: Export pipe delimited data</title>
      <link>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825161#M4856004</link>
      <description>&lt;P&gt;Hi Volker,&lt;/P&gt;
&lt;P&gt;That was actually my thinking too, that some how the command was being misinterpreted.&lt;/P&gt;
&lt;P&gt;Thanks for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2016 16:58:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/export-pipe-delimited-data/qaa-p/13825161#M4856004</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2016-02-22T16:58:38Z</dc:date>
    </item>
  </channel>
</rss>

