The forum will experience an outage sometime between February 10 at 7:00pm EST and February 12 at 11:59 EST for installation of security updates. The actual time and duration of the outage are unknown but attempts will be made to minimize the downtime. We apologize for any inconvenience.

Just a slight issue:

Something I frequently need: a comma-separated list of all column names ordered by column id (i.e. position) for one particular table, and I'm usually needing it while writing (ad-hoc) SQL code - so I'm not asking for a Sybase Central wizard approach:)

I'm using this frequently to build "SELECT col1 ... coln FROM MyTable ... " statements or the like.

Is there any builtin function - or anything better than the catalog query I'm about to post?

asked 09 Jul '12, 09:56

Volker%20Barth's gravatar image

Volker Barth
29.3k287438644
accept rate: 32%

edited 09 Jul '12, 10:36


What I'm typically using is something like the following:

select list (column_name, ', ' order by column_id)
from systabcol key join systab
where table_name = 'MyTableName';

Works fine for v10 and above (and I'm posting it here to remind me of that tiny template), but I guess there are better builtin ways...

permanent link

answered 09 Jul '12, 09:58

Volker%20Barth's gravatar image

Volker Barth
29.3k287438644
accept rate: 32%

I've used this approach before:

  1. select * from 'mytablename';
  2. highlight first row, right click and 'copy selected rows'
  3. paste results

You'll get two rows. Top row is column names. Bottom row is data. Delete data and you have a comma separated list of column names.

permanent link

answered 30 Jul '12, 06:39

zippidydo's gravatar image

zippidydo
362151521
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×24

question asked: 09 Jul '12, 09:56

question was seen: 10,551 times

last updated: 30 Jul '12, 06:39