<?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: table description as result set in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829362#M4860205</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;order by tname, cols&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;tname is superfluous here, as you already group by tname.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Sep 2021 08:19:40 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2021-09-22T08:19:40Z</dc:date>
    <item>
      <title>table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaq-p/13829350</link>
      <description>&lt;P&gt;Is it possible to have the description of a table as a result set?&lt;/P&gt;
&lt;P&gt;Something like this&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;select * from (describe table mytable)&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 21 Sep 2021 10:50:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaq-p/13829350</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2021-09-21T10:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829351#M4860194</link>
      <description>&lt;P&gt;The DESCRIBE statement cannot be coded inside a server-side SQL operation because it a client-side ISQL statement.&lt;/P&gt;
&lt;P&gt;However, you can SELECT FROM SYS.SYSCOLUMNS to get the same result:&lt;/P&gt;
&lt;PRE&gt;DESCRIBE TABLE rroad_sample_memo;
SELECT LEFT ( cname, 32 ) AS "Column",
       LEFT ( coltype, 32 ) AS "Type",
       IF nulls = 'N' THEN 0 ELSE 1 ENDIF AS "Nullable",
       IF in_primary_key = 'N' THEN 0 ELSE 1 ENDIF AS "Primary Key"
  FROM SYS.SYSCOLUMNS
 WHERE tname = 'rroad_sample_memo'
 ORDER BY colno;

Column                           Type                             Nullable Primary Key 
-------------------------------- -------------------------------- -------- ----------- 
sampling_id                      unsigned int                            0           0 
sample_set_number                unsigned bigint                         0           1 
memo                             long varchar                            0           0 


Column                           Type                             Nullable Primary Key 
-------------------------------- -------------------------------- -------- ----------- 
sampling_id                      unsigned int                            0           0 
sample_set_number                unsigned bigint                         0           1 
memo                             long varchar                            0           0 
(3 rows)
Execution time: 0.002 seconds
&lt;/PRE&gt;

&lt;P&gt;FYI the system catalog views contain vastly more information than any DESCRIBE statement.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 11:22:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829351#M4860194</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2021-09-21T11:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829353#M4860196</link>
      <description>&lt;P&gt;FWIW, there's also the &lt;A href="https://sqlanywhere-forum.sap.com/questions/30938"&gt;sa_get_table_definition system function&lt;/A&gt; that returns basically the CREATE TABLE statement etc. as a long varchar for the according table, but of course that is not the result set you are looking for.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Sep 2021 11:36:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829353#M4860196</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2021-09-21T11:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829352#M4860195</link>
      <description>&lt;P&gt;Thank you!!&lt;/P&gt;
&lt;P&gt;The goal was to generate an insert statements for big tables to be used in a python script, at the end Syscolumns helped me a lot.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;create or replace table table1(id1 int, name1 varchar(10));&lt;/P&gt;
&lt;P&gt;create or replace table table2(id2 int, name2 varchar(10), surname2 varchar(10));&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;create or replace table table100(id100 int, name100 varchar(10), surname100 varchar(10), depart100 varchar(10));&lt;/P&gt;
&lt;P&gt;select 'insert into ' || tname || '(' || list(&lt;STRONG&gt;cols&lt;/STRONG&gt;) || ') values ('  || list (&lt;STRONG&gt;vals&lt;/STRONG&gt;) || ')' from
(select tname, cname &lt;STRONG&gt;cols&lt;/STRONG&gt;, (if coltype = 'varchar' then '''%S''' else '%S' endif) as &lt;STRONG&gt;vals&lt;/STRONG&gt; from sys.syscolumns where tname in ('table1', 'table2', 'table100')) T1 group by tname;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 22 Sep 2021 02:48:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829352#M4860195</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2021-09-22T02:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829354#M4860197</link>
      <description>&lt;P&gt;Yes, but it returns the result in a one single column/row, which doesn't help in my case&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 02:53:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829354#M4860197</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2021-09-22T02:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829355#M4860198</link>
      <description>&lt;P&gt;And again LIST() is such a helpful aggregate function - you might make sure that both lists are sorted identically by adding an ORDER BY expression.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 03:09:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829355#M4860198</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2021-09-22T03:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829356#M4860199</link>
      <description>&lt;P&gt;Is the GROUP BY TNAME not enough to guarantee that the column names are correctly assigned to each TableName?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 03:48:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829356#M4860199</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2021-09-22T03:48:32Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829357#M4860200</link>
      <description>&lt;P&gt;Oh, you mean in order to keep the same order between &lt;STRONG&gt;vals&lt;/STRONG&gt; and &lt;STRONG&gt;cols&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;The question is here how does the &lt;STRONG&gt;list&lt;/STRONG&gt; function work? Doesn't it take the same order as they appear in the subquery (of table T1)?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 04:17:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829357#M4860200</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2021-09-22T04:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829358#M4860201</link>
      <description>&lt;P&gt;In my understanding, unless you specify an ORDER BY clause, the SQL query engine is free to order result sets - and for LIKE, to order the different entries - to its preference according to the used access plans, i.e. it does not need to order them in any meaningful way.&lt;/P&gt;
&lt;P&gt;And I'm quite sure you want column names and values in the "correct order" here.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 04:35:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829358#M4860201</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2021-09-22T04:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829359#M4860202</link>
      <description>&lt;P&gt;Yes, I need to have them in the "correct order" &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But where to add the order by exactly?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 05:30:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829359#M4860202</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2021-09-22T05:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829360#M4860203</link>
      <description>&lt;P&gt;The full LIST syntax is&lt;/P&gt;
&lt;PRE&gt;LIST( 
[ALL | DISTINCT ] string-expression
[, delimiter-string ]
[ ORDER BY order-by-expression [ ASC | DESC ], ... ] )&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Sep 2021 05:41:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829360#M4860203</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2021-09-22T05:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829361#M4860204</link>
      <description>&lt;P&gt;Thanks, should it then look like this?&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;select 'insert into ' || tname || '(' || list(cols &lt;STRONG&gt;order by tname, cols&lt;/STRONG&gt;) || ') values (' || list (vals &lt;STRONG&gt;order by tname, cols&lt;/STRONG&gt;) || ')' from (select tname, cname cols, (if coltype = 'varchar' then '''%S''' else '%S' endif) as vals from sys.syscolumns where tname in ('table1', 'table2', 'table100')) T1 group by tname;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 22 Sep 2021 07:05:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829361#M4860204</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2021-09-22T07:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829362#M4860205</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;order by tname, cols&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;tname is superfluous here, as you already group by tname.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 08:19:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829362#M4860205</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2021-09-22T08:19:40Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829363#M4860206</link>
      <description>&lt;P&gt;So you mean only &lt;STRONG&gt;order by cols&lt;/STRONG&gt;?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 09:05:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829363#M4860206</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2021-09-22T09:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829364#M4860207</link>
      <description>&lt;P&gt;Yes, that's what I mean.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 09:14:20 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829364#M4860207</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2021-09-22T09:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: table description as result set</title>
      <link>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829365#M4860208</link>
      <description>&lt;P&gt;adding order by cols helps to keep both lists in the same order, but both come in a false order (alphabeitcally instead of the real order).&lt;/P&gt;
&lt;P&gt;So, the correct statement should look like this:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;select 'insert into ' || tname || '(' || list(cols order by colno) || ') values (' || list (vals order by colno) || ')' from (select colno, tname, cname cols, (if coltype = 'varchar' then '''%s''' else '%s' endif) as vals from sys.syscolumns where tname in ('table1', 'table2', 'table100')) T1 group by tname;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 24 Sep 2021 04:59:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/table-description-as-result-set/qaa-p/13829365#M4860208</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2021-09-24T04:59:03Z</dc:date>
    </item>
  </channel>
</rss>

