<?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: insert comma seperated values in table in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845681#M4876524</link>
    <description>&lt;P&gt;Okay Thanks a lot. &lt;/P&gt;</description>
    <pubDate>Sat, 16 Feb 2013 11:14:10 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2013-02-16T11:14:10Z</dc:date>
    <item>
      <title>insert comma seperated values in table</title>
      <link>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaq-p/13845675</link>
      <description>&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="nv"&gt;@id&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="mi"&gt;1&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;2&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;3&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;4&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;5&lt;/SPAN&gt;
&lt;SPAN class="nv"&gt;@name&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'NY, NJ, VA, DC,CA'&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;I have a temp table called &lt;CODE&gt;#tmp (id int, name varchar(4))&lt;/CODE&gt;. I want to insert these above comma delimited values in this temp table, so 1 has corresponding value = NY, 2 has NJ etc...so total 5 rows will be inserted. What is the best way to code that in SQL Anywhere?&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2013 19:09:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaq-p/13845675</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-02-12T19:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: insert comma seperated values in table</title>
      <link>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845676#M4876519</link>
      <description>&lt;P&gt;You want to use the &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbreference/sa-split-list-system-procedure.html*d5e77820"&gt;&lt;CODE&gt;sa_split_list&lt;/CODE&gt; function&lt;/A&gt; to break the strings into a result set. Since there are two of them, you'll need to join them. This seems to work:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="k"&gt;insert&lt;/SPAN&gt; &lt;SPAN class="k"&gt;into&lt;/SPAN&gt; &lt;SPAN class="o"&gt;#&lt;/SPAN&gt;&lt;SPAN class="n"&gt;tmp&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;id&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="n"&gt;name&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="k"&gt;select&lt;/SPAN&gt; &lt;SPAN class="n"&gt;ID&lt;/SPAN&gt;&lt;SPAN class="p"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;row_value&lt;/SPAN&gt; &lt;SPAN class="n"&gt;id&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;VAL&lt;/SPAN&gt;&lt;SPAN class="p"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;row_value&lt;/SPAN&gt; &lt;SPAN class="n"&gt;name&lt;/SPAN&gt; 
    &lt;SPAN class="k"&gt;from&lt;/SPAN&gt; &lt;SPAN class="n"&gt;sa_split_list&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="o"&gt;@&lt;/SPAN&gt;&lt;SPAN class="n"&gt;name&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;VAL&lt;/SPAN&gt; &lt;SPAN class="k"&gt;join&lt;/SPAN&gt; &lt;SPAN class="n"&gt;sa_split_list&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="o"&gt;@&lt;/SPAN&gt;&lt;SPAN class="n"&gt;id&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;ID&lt;/SPAN&gt; &lt;SPAN class="k"&gt;on&lt;/SPAN&gt; &lt;SPAN class="n"&gt;ID&lt;/SPAN&gt;&lt;SPAN class="p"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;line_num&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="n"&gt;VAL&lt;/SPAN&gt;&lt;SPAN class="p"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;line_num&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 12 Feb 2013 20:32:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845676#M4876519</guid>
      <dc:creator>graeme_perrow</dc:creator>
      <dc:date>2013-02-12T20:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: insert comma seperated values in table</title>
      <link>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845677#M4876520</link>
      <description>&lt;P&gt;Try something like this:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;insert&lt;/SPAN&gt; &lt;SPAN class="n"&gt;into&lt;/SPAN&gt; &lt;SPAN class="c1"&gt;#tmp( id, name )&lt;/SPAN&gt;
&lt;SPAN class="nb"&gt;select&lt;/SPAN&gt; &lt;SPAN class="n"&gt;a&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;row_value&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="n"&gt;b&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;row_value&lt;/SPAN&gt;
  &lt;SPAN class="n"&gt;from&lt;/SPAN&gt; &lt;SPAN class="n"&gt;sa_split_list&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;@id&lt;/SPAN&gt; &lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;a&lt;/SPAN&gt;
  &lt;SPAN class="nb"&gt;join&lt;/SPAN&gt; &lt;SPAN class="n"&gt;sa_split_list&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;@name&lt;/SPAN&gt; &lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;b&lt;/SPAN&gt;
    &lt;SPAN class="n"&gt;on&lt;/SPAN&gt; &lt;SPAN class="n"&gt;a&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;line_num&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;b&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;line_num&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;Note that I have not tested this. You can read more information about &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbreference/sa-split-list-system-procedure.html"&gt;sa_split_list&lt;/A&gt; in the &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbreference/sa-split-list-system-procedure.html"&gt;docs&lt;/A&gt;.&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;I noticed that you have some embedded spaces in your comma-delimited strings. If you don't want those included in your tmp table then you will can use &lt;A href="http://dcx.sybase.com/index.html#1201/en/dbreference/trim-function.html"&gt;trim&lt;/A&gt; to remove any that exists.
Example:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;insert&lt;/SPAN&gt; &lt;SPAN class="n"&gt;into&lt;/SPAN&gt; &lt;SPAN class="c1"&gt;#tmp( id, name )&lt;/SPAN&gt;
&lt;SPAN class="nb"&gt;select&lt;/SPAN&gt; &lt;SPAN class="n"&gt;trim&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="n"&gt;a&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;row_value&lt;/SPAN&gt; &lt;SPAN class="p"&gt;),&lt;/SPAN&gt; &lt;SPAN class="n"&gt;trim&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="n"&gt;b&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;row_value&lt;/SPAN&gt; &lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="n"&gt;from&lt;/SPAN&gt; &lt;SPAN class="n"&gt;sa_split_list&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;@id&lt;/SPAN&gt; &lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;a&lt;/SPAN&gt;
  &lt;SPAN class="nb"&gt;join&lt;/SPAN&gt; &lt;SPAN class="n"&gt;sa_split_list&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt; &lt;SPAN class="nv"&gt;@name&lt;/SPAN&gt; &lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;b&lt;/SPAN&gt;
    &lt;SPAN class="n"&gt;on&lt;/SPAN&gt; &lt;SPAN class="n"&gt;a&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;line_num&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;b&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;line_num&lt;/SPAN&gt;&lt;SPAN class="p"&gt;;&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 12 Feb 2013 20:38:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845677#M4876520</guid>
      <dc:creator>MarkCulp</dc:creator>
      <dc:date>2013-02-12T20:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: insert comma seperated values in table</title>
      <link>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845679#M4876522</link>
      <description>&lt;P&gt;Looks like Graeme hit enter a few minutes before I did &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; ... I took too long to look up the references in the docs!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2013 20:40:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845679#M4876522</guid>
      <dc:creator>MarkCulp</dc:creator>
      <dc:date>2013-02-12T20:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: insert comma seperated values in table</title>
      <link>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845680#M4876523</link>
      <description>&lt;P&gt;Thats perfect. Thanks a lot all.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 17:12:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845680#M4876523</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-02-13T17:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: insert comma seperated values in table</title>
      <link>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845678#M4876521</link>
      <description>&lt;PRE&gt;CREATE TABLE #tmp_tbl
          ( qualifier_state_id    integer
          , event_id              integer
          , group_id              integer
          , state_number          integer
          , qualifier_state_name  varchar(255)
          )
INSERT INTO #tmp_tbl(qualifier_state_name) VALUES ('SAMLL')
INSERT INTO #tmp_tbl(qualifier_state_name) VALUES ('YELLO')
&lt;/PRE&gt;

&lt;P&gt;Thanks but I have qualifier_state_name in my temp table
and my qualifier_state_ids are coming from variavle @qualifier_state_ids = '58,61'
Where 58= SMALL and 61= Yello&lt;/P&gt;
&lt;P&gt;Now I need to update below temp table and make qualifier_state_id =58 for small and 61 for Yello
I tried below but not workin&lt;/P&gt;
&lt;PRE&gt;UPDATE #tmp_tbl                             a
                    , sa_split_list(@lQualifierStateIds)   b
                  SET a.qualifier_state_id   = TRIM(b.row_value)-- this updates both state_ids =61 whichh is wrong.
&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Feb 2013 16:52:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845678#M4876521</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-02-14T16:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: insert comma seperated values in table</title>
      <link>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845681#M4876524</link>
      <description>&lt;P&gt;Okay Thanks a lot. &lt;/P&gt;</description>
      <pubDate>Sat, 16 Feb 2013 11:14:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/insert-comma-seperated-values-in-table/qaa-p/13845681#M4876524</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-02-16T11:14:10Z</dc:date>
    </item>
  </channel>
</rss>

