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
31.3k312458674
accept rate: 33%

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
31.3k312458674
accept rate: 33%

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:

×25

question asked: 09 Jul '12, 09:56

question was seen: 11,566 times

last updated: 30 Jul '12, 06:39