<?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: Need help getting this to work in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844033#M4874876</link>
    <description>&lt;P&gt;Just some questions (and I don't know if they count as ideas...):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;Does it work when you only add one row (i.e. when you just loop over one element??&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;I'm not sure if "SELECT INTO" fits to the ExecuteNonQuery() method - does it work if you split the first SACommand into two separate commands?&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Does it work with "DECLARE LOCAL TEMPORARY TABLE" instead of select into? - (I agree on your point of the advantage of a schema-agnostic approach.)&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
    <pubDate>Thu, 10 Jan 2013 04:00:58 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2013-01-10T04:00:58Z</dc:date>
    <item>
      <title>Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaq-p/13844029</link>
      <description>&lt;P&gt;I am working on a process in my applicaiton that is used to update a table in our database called &lt;CODE&gt;ListDetails&lt;/CODE&gt;.  The idea behind this process is that the data is in a text file that has been parsed into a fixed, known format by another, outside process.  We take this text file, parse it into records, and insert each into a temporary table.  When all of the data is loaded into the temporary table, we use a stored procedure to merge the data from the temporary table into the live table.&lt;/P&gt;
&lt;P&gt;This process was originally built using SQL Server and works there.  I am porting it to Sql Anywhere 12.0.1.  This process is built in C#.&lt;/P&gt;
&lt;P&gt;My problem is in the loading into the temporary table phase.  Here's the code for creating the temporary table:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;new&lt;/SPAN&gt; &lt;SPAN class="n"&gt;SACommand&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="s"&gt;@"DROP TABLE IF EXISTS tempimport;&lt;/SPAN&gt;
       &lt;SPAN class="n"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="o"&gt;*&lt;/SPAN&gt; &lt;SPAN class="n"&gt;INTO&lt;/SPAN&gt; &lt;SPAN class="n"&gt;LOCAL&lt;/SPAN&gt; &lt;SPAN class="n"&gt;TEMPORARY&lt;/SPAN&gt; &lt;SPAN class="n"&gt;TABLE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;tempimport&lt;/SPAN&gt; &lt;SPAN class="n"&gt;FROM&lt;/SPAN&gt; &lt;SPAN class="n"&gt;ListDetails&lt;/SPAN&gt; &lt;SPAN class="n"&gt;WHERE&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;1&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;0&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;&lt;SPAN class="s"&gt;", saConnection, saTransaction ).ExecuteNonQuery();&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;This executes without any errors.&lt;/P&gt;
&lt;P&gt;In SQL server, we used bulk copy to load the data.  It turns out that a dedicated &lt;CODE&gt;SACommand&lt;/CODE&gt; that runs an &lt;CODE&gt;INSERT&lt;/CODE&gt; statement is actually faster that the SA &lt;A href="http://ADO.net" target="_blank"&gt;ADO.net&lt;/A&gt; &lt;CODE&gt;SABulkCopy&lt;/CODE&gt; class, so I created just that:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;SACommand&lt;/SPAN&gt; &lt;SPAN class="n"&gt;insertCommand&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="k"&gt;new&lt;/SPAN&gt; &lt;SPAN class="n"&gt;SACommand&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"INSERT INTO tempimport "&lt;/SPAN&gt; &lt;SPAN class="o"&gt;+&lt;/SPAN&gt;
                                             &lt;SPAN class="s"&gt;"( ListDetailId, ListId, CountryId, LocaleCode, Plate, HashedPlate, AlarmClassId, BeginDate, EndDate, "&lt;/SPAN&gt; &lt;SPAN class="o"&gt;+&lt;/SPAN&gt;
                                               &lt;SPAN class="s"&gt;"ListPriorityId, VehicleTypeId, PlateClassId, MakeId, ModelId, Year, ColorId, "&lt;/SPAN&gt; &lt;SPAN class="o"&gt;+&lt;/SPAN&gt;
                                               &lt;SPAN class="s"&gt;"Notes, OfficerNotes, CreateDate, Subscriber, InstanceId ) "&lt;/SPAN&gt; &lt;SPAN class="o"&gt;+&lt;/SPAN&gt;
                                         &lt;SPAN class="s"&gt;"VALUES "&lt;/SPAN&gt; &lt;SPAN class="o"&gt;+&lt;/SPAN&gt;
                                             &lt;SPAN class="s"&gt;"( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) "&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;saConnection&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;saTransaction&lt;/SPAN&gt; &lt;SPAN class="p"&gt;);&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;The next code creates a bunch of &lt;CODE&gt;SAParameter&lt;/CODE&gt; objects, one for each ?, and adds them to the &lt;CODE&gt;SACommand&lt;/CODE&gt; object's &lt;CODE&gt;Parameters&lt;/CODE&gt; collection.  Then, in a loop, I parse the file, load the data into each &lt;CODE&gt;SAParameter&lt;/CODE&gt; object's &lt;CODE&gt;Value&lt;/CODE&gt; property as needed, and finally execute the &lt;CODE&gt;SACommand.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;The problem is that when I execute the &lt;CODE&gt;SACommand&lt;/CODE&gt;, I get an error that states that the table &lt;CODE&gt;tempimport&lt;/CODE&gt; does not exist.  What am I doing wrong?  Should I use a &lt;CODE&gt;DECLARE LOCAL TEMPRORARY TABLE&lt;/CODE&gt; command?  The advantage of the way I'm doing it is that this code doesn't have to change if the &lt;CODE&gt;ListDetails&lt;/CODE&gt; table ever changes.&lt;/P&gt;
&lt;P&gt;Just to make sure it's clear, the &lt;CODE&gt;SAConnection&lt;/CODE&gt; and &lt;CODE&gt;SATransaction&lt;/CODE&gt; objects in the two &lt;CODE&gt;SACommands&lt;/CODE&gt; are the same objects, and neither the transaction or the connection end until after all of the work is done.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 13:59:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaq-p/13844029</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-01-09T13:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844031#M4874874</link>
      <description>&lt;P&gt;Try using &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbusage/performance-s-5753386.html"&gt;request-level logging&lt;/A&gt; to see what SQL statements are sent to the server. If the SQL in the SACommand is wrapped in a compound statement (begin end) when it hits the server, then tempimport will "go out of scope" when the compound statement ends.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 14:52:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844031#M4874874</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2013-01-09T14:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844032#M4874875</link>
      <description>&lt;P&gt;I've turned on request-level logging and there are no begin end statements wrapping either of the two statements.  Any other ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jan 2013 15:08:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844032#M4874875</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-01-09T15:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844033#M4874876</link>
      <description>&lt;P&gt;Just some questions (and I don't know if they count as ideas...):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P&gt;Does it work when you only add one row (i.e. when you just loop over one element??&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;I'm not sure if "SELECT INTO" fits to the ExecuteNonQuery() method - does it work if you split the first SACommand into two separate commands?&lt;/P&gt;
&lt;/LI&gt;
&lt;LI&gt;
&lt;P&gt;Does it work with "DECLARE LOCAL TEMPORARY TABLE" instead of select into? - (I agree on your point of the advantage of a schema-agnostic approach.)&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 10 Jan 2013 04:00:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844033#M4874876</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2013-01-10T04:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844034#M4874877</link>
      <description>&lt;P&gt;@VolkerBarth: I haven't tried a "&lt;CODE&gt;DECLARE LOCAL TEMPORARY TABLE&lt;/CODE&gt;" but it does work with a "&lt;CODE&gt;CREATE LOCAL TEMPORARY TABLE&lt;/CODE&gt;".  I'm leaving it like that for now because it works.  However, I would like to see we can get the "&lt;CODE&gt;SELECT INTO&lt;/CODE&gt;" to work.  It does look like the temporary table is going out of scope.  It works when I run it in ISQL.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jan 2013 08:26:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844034#M4874877</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-01-10T08:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844035#M4874878</link>
      <description>&lt;P&gt;A question for your problem :&lt;/P&gt;
&lt;P&gt;The connection in Interactive SQL and in the .NET Code is for users that have the same level of rights ?&lt;/P&gt;
&lt;P&gt;For a better control you can create a procedure that :&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="mi"&gt;1&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="k"&gt;use&lt;/SPAN&gt; &lt;SPAN class="n"&gt;the&lt;/SPAN&gt; &lt;SPAN class="n"&gt;sa_get_table_definition&lt;/SPAN&gt;&lt;SPAN class="p"&gt;()&lt;/SPAN&gt; &lt;SPAN class="n"&gt;on&lt;/SPAN&gt; &lt;SPAN class="n"&gt;your&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'ListDetails'&lt;/SPAN&gt; &lt;SPAN class="n"&gt;Table&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;

&lt;SPAN class="mi"&gt;2&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="k"&gt;do&lt;/SPAN&gt; &lt;SPAN class="n"&gt;some&lt;/SPAN&gt; &lt;SPAN class="n"&gt;string&lt;/SPAN&gt; &lt;SPAN class="n"&gt;manipulations&lt;/SPAN&gt; &lt;SPAN class="n"&gt;on&lt;/SPAN&gt; &lt;SPAN class="n"&gt;the&lt;/SPAN&gt; &lt;SPAN class="n"&gt;procedure&lt;/SPAN&gt; &lt;SPAN class="k"&gt;return&lt;/SPAN&gt; &lt;SPAN class="n"&gt;to&lt;/SPAN&gt; &lt;SPAN class="n"&gt;build&lt;/SPAN&gt; &lt;SPAN class="n"&gt;the&lt;/SPAN&gt; &lt;SPAN class="n"&gt;dynamic&lt;/SPAN&gt; &lt;SPAN class="n"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;LOCAL&lt;/SPAN&gt; &lt;SPAN class="n"&gt;TEMPORARY&lt;/SPAN&gt; &lt;SPAN class="n"&gt;TABLE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;statment&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt; &lt;SPAN class="n"&gt;From&lt;/SPAN&gt; &lt;SPAN class="n"&gt;the&lt;/SPAN&gt; &lt;SPAN class="n"&gt;documentation&lt;/SPAN&gt; &lt;SPAN class="p"&gt;:&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;"If you want a procedure to create a local temporary table that persists after the procedure completes, use the CREATE LOCAL TEMPORARY TABLE statement instead."&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="mi"&gt;3&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="k"&gt;do&lt;/SPAN&gt; &lt;SPAN class="n"&gt;an&lt;/SPAN&gt; &lt;SPAN class="n"&gt;EXECUTE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;IMMEDIATE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;statment&lt;/SPAN&gt; &lt;SPAN class="n"&gt;on&lt;/SPAN&gt; &lt;SPAN class="n"&gt;this&lt;/SPAN&gt; &lt;SPAN class="n"&gt;string&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 14 Jan 2013 09:28:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844035#M4874878</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-01-14T09:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844036#M4874879</link>
      <description>&lt;P&gt;If you name the temp table starting with a # sign it will be build automatically for you. &lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="o"&gt;*&lt;/SPAN&gt; &lt;SPAN class="n"&gt;INTO&lt;/SPAN&gt; &lt;SPAN class="c1"&gt;#tempimport FROM ListDetails WHERE 1 = 0;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;HTH&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jan 2013 14:51:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844036#M4874879</guid>
      <dc:creator>thomas_duemesnil</dc:creator>
      <dc:date>2013-01-14T14:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844037#M4874880</link>
      <description>&lt;P&gt;...but the same (i.e. automatic creation of the temp table) is true for the clause he is using in the OP:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;SELECT * INTO LOCAL TEMPORARY TABLE tempimport FROM ListDetails WHERE 1 = 0;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 15 Jan 2013 04:20:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844037#M4874880</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2013-01-15T04:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844030#M4874873</link>
      <description>&lt;P&gt;Just to share, the solution was to hard code the layout of the temporary table in a DDL statement, i.e., &lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;CREATE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;LOCAL&lt;/SPAN&gt; &lt;SPAN class="n"&gt;TEMPORARY&lt;/SPAN&gt; &lt;SPAN class="n"&gt;TABLE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;tempimport&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;
    &lt;SPAN class="o"&gt;.&lt;/SPAN&gt; &lt;SPAN class="o"&gt;.&lt;/SPAN&gt; &lt;SPAN class="o"&gt;.&lt;/SPAN&gt;
&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;This means that I will have to update the DLL if we ever change the layout of the table.  Even though the &lt;CODE&gt;SELECT INTO&lt;/CODE&gt; statement works in the Interactive SQL program, it will not work in a program.  Frankly, this sucks, but it's the only way to get the job done.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2013 17:18:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844030#M4874873</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-02-07T17:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Need help getting this to work</title>
      <link>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844038#M4874881</link>
      <description>&lt;P&gt;The connection is established in C# and always uses the DBA user ID to connect.&lt;BR /&gt;
&lt;/P&gt;
&lt;P&gt;Calling sa_get_table_definition() never occurred to me.  That's an interesting idea.  I'll have to look at that one of these days.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jul 2013 09:13:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/need-help-getting-this-to-work/qaa-p/13844038#M4874881</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-07-12T09:13:22Z</dc:date>
    </item>
  </channel>
</rss>

