dbTalk Databases Forums  

Getting info out of a Sybase table in CSV format? How to?

comp.databases.sybase comp.databases.sybase


Discuss Getting info out of a Sybase table in CSV format? How to? in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tom Brehony
 
Posts: n/a

Default Getting info out of a Sybase table in CSV format? How to? - 08-09-2004 , 06:36 AM






I am working on Sybase 11.5.1 on Aix 4.2.1

As far as I know it is not possible to get bcp to output data in
comma seperated variable length (CSV) format. Is this correct?

If it is, are there any utilities which do allow you to bulk extract info
out of a Sybase table in CSV format? Preferably freeware one!

Any advice / pointers would be appreciated, thanks!

Tom.



Reply With Quote
  #2  
Old   
Rob Verschoor
 
Posts: n/a

Default Re: Getting info out of a Sybase table in CSV format? How to? - 08-09-2004 , 07:27 AM






"Tom Brehony" <tombrehony.nospam (AT) eircom (DOT) nospam.net> wrote

Quote:
I am working on Sybase 11.5.1 on Aix 4.2.1

As far as I know it is not possible to get bcp to output data in
comma seperated variable length (CSV) format. Is this correct?

If it is, are there any utilities which do allow you to bulk extract info
out of a Sybase table in CSV format? Preferably freeware one!

Any advice / pointers would be appreciated, thanks!

Tom.

Not entirely correct.
By specifying the bcp options '-c -t,' you get something that looks very
much like a CSV file, with all column values separated by commas. You may
need to manually remove the trailing comm (easily done with sed or awk).
CSV can actually go a bit further, and quotes a value if it contains a comma
itself. Using '-c -t\",\" ' gets quite close. You'd need to put in a leading
quote manually (again, use sed or awk).

Rob
-------------------------------------------------------------
Rob Verschoor

Certified Sybase Professional DBA for ASE 12.5/12.0/11.5/11.0
and Replication Server 12.5

Author of Sybase books (order online at www.sypron.nl/shop):
"Tips, Tricks & Recipes for Sybase ASE"
"The Complete Sybase Replication Server Quick Reference Guide"
"The Complete Sybase ASE Quick Reference Guide"

mailto:rob (AT) YOUR (DOT) SPAM.sypron.nl.NOT.FOR.ME
http://www.sypron.nl
Sypron B.V., P.O.Box 10695, 2501HR Den Haag, The Netherlands
-------------------------------------------------------------




Reply With Quote
  #3  
Old   
Willie Kraatz
 
Posts: n/a

Default Re: Getting info out of a Sybase table in CSV format? How to? - 08-09-2004 , 08:53 AM



a simple approach might be to define a view on the table with a null column
at the beginning.

create view xauthors as
select constant = null
, au_id
,au_lname
,au_fname
,phone
,address
,city
,state
,country
,postalcode
from authors

Create your fmt file as
10.0
10
1 SYBCHAR 0 3 "\"" 1 constant
2 SYBCHAR 0 11 "\",\"" 2 au_id
3 SYBCHAR 0 40 "\",\"" 3 au_lname
4 SYBCHAR 0 20 "\",\"" 4 au_fname
5 SYBCHAR 0 12 "\",\"" 5 phone
6 SYBCHAR 1 40 "\",\"" 6 address
7 SYBCHAR 1 20 "\",\"" 7 city
8 SYBCHAR 1 2 "\",\"" 8 state
9 SYBCHAR 1 12 "\",\"" 9 country
10 SYBCHAR 1 10 "\"\n\r" 10 postalcode

Then run a standard bcp out.

bcp pubs2..xauthors out xauthors.dat -f xauthors.fmt -U xxxx - Pxxxx


"Rob Verschoor" <rob (AT) DO (DOT) NOT.SPAM.sypron.nl.REMOVE.THIS.DECOY> wrote in
message news:T4KRc.58564$i7.12992 (AT) amsnews05 (DOT) chello.com...
Quote:
"Tom Brehony" <tombrehony.nospam (AT) eircom (DOT) nospam.net> wrote in message
news:2np5v8F31umeU1 (AT) uni-berlin (DOT) de...
I am working on Sybase 11.5.1 on Aix 4.2.1

As far as I know it is not possible to get bcp to output data in
comma seperated variable length (CSV) format. Is this correct?

If it is, are there any utilities which do allow you to bulk extract
info
out of a Sybase table in CSV format? Preferably freeware one!

Any advice / pointers would be appreciated, thanks!

Tom.


Not entirely correct.
By specifying the bcp options '-c -t,' you get something that looks very
much like a CSV file, with all column values separated by commas. You may
need to manually remove the trailing comm (easily done with sed or awk).
CSV can actually go a bit further, and quotes a value if it contains a
comma
itself. Using '-c -t\",\" ' gets quite close. You'd need to put in a
leading
quote manually (again, use sed or awk).

Rob
-------------------------------------------------------------
Rob Verschoor

Certified Sybase Professional DBA for ASE 12.5/12.0/11.5/11.0
and Replication Server 12.5

Author of Sybase books (order online at www.sypron.nl/shop):
"Tips, Tricks & Recipes for Sybase ASE"
"The Complete Sybase Replication Server Quick Reference Guide"
"The Complete Sybase ASE Quick Reference Guide"

mailto:rob (AT) YOUR (DOT) SPAM.sypron.nl.NOT.FOR.ME
http://www.sypron.nl
Sypron B.V., P.O.Box 10695, 2501HR Den Haag, The Netherlands
-------------------------------------------------------------





Reply With Quote
  #4  
Old   
Thomas Gagne
 
Posts: n/a

Default Re: Getting info out of a Sybase table in CSV format? How to? - 08-11-2004 , 07:56 AM



With "is" I would do something like:

dexter:master 13.1> set rowcount 10
dexter:master 13.2> go
dexter:master 14.1> :set headers off
dexter:master 14.1> :set rowcount off
dexter:master 14.1> rintf %s,%s,"%s"
dexter:master 14.1> select id, uid, name from sysobjects
dexter:master 14.2> go
1,1,"sysobjects"
2,1,"sysindexes"
3,1,"syscolumns"
4,1,"systypes"
5,1,"sysprocedures"
6,1,"syscomments"
7,1,"syssegments"
8,1,"syslogs"
9,1,"sysprotects"
10,1,"sysusers"

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.