The forum will be down for maintenance over the weekend of August 18-20, 2017. The forum will be shut down on the evening (EDT) of Friday, August 18. Downtime is unknown but may be up to two days. The forum will be restarted as soon as maintenance is complete.

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
30.9k311457668
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
30.9k311457668
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
377151521
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: 11,399 times

last updated: 30 Jul '12, 06:39