Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output table to a csv file

Status
Not open for further replies.

n2nuk

IS-IT--Management
Dec 24, 2002
190
0
0
GB
Hi,

I am new to Sybase (having some previous exp of Oracle) and am having difficulty extracting data from our database system which is based on Adaptive server 7.02.
I have logged onto Interactive SQL to write my script which is basically a select everything from one table. Because I want the data to be exported as a CSV I am using the following syntax:

spool addresses.txt
select address_ref||','||
person_ref||','||
organisation_ref||','||
type
from address
where address_ref between 20 and 30;
spool off

what is correct command to send the data to an output file, also is the use of pipes valid to concatenate the data?

I would appreciate any feedback or help.

thanks

Naz


 
Easiest way I would do this is to put the contents of select statement into tempdb, then use the bcp utility to extract from the OS level.

select address_ref,
person_ref,
organisation_ref,
type
into tempdb..address_info
from address
where address_ref between 20 and 30;
go

bcp tempdb..address_info out address_info.out -c -t',' -U<username> -S<servername>

You could use the SQL as you stated, but it may require massaging the output...

-mjm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top