Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Sybase > sql result to csv or excel file using shell script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-22-07, 02:03
tiger66 tiger66 is offline
Registered User
 
Join Date: Dec 2007
Posts: 24
sql result to csv or excel file using shell script

Hi
I need some help from an expert in sybase and shell script.
Does anyone know how to save the data from a sql to a csv or excel file using shell script?

I can only save the data to a txt file. The problem is that the data in the file are not very readable. So, I want to save the data in a csv or excel file

the shell script I have is:

sql_file="sqls.sql"
output="out.txt"
`isql -U ${USER} -P ${PWD} -D ${DB} -S ${SEVER} -i $sql_file -o $output`

If you can help, please let me know. I will be really appreciated

Thanks
Reply With Quote
  #2 (permalink)  
Old 12-22-07, 08:11
trvishi trvishi is offline
Registered User
 
Join Date: Sep 2003
Location: Switzerland
Posts: 371
Easy way is to add comma to your sql statement.

For eg.,

SELECT col1,',',col2,',',col3 from mytable
Reply With Quote
  #3 (permalink)  
Old 12-23-07, 23:09
tiger66 tiger66 is offline
Registered User
 
Join Date: Dec 2007
Posts: 24
Thank you trvishi, after adding the ',' my data become very organized.

The last problem I have with my output is that, the title of the data are not separated.
I try to insert a ',' between each title with the following query.
select col1 as Name1',',', col2 as Name2', from myTable

Unfortunately, I am getting an incorrect synax error near Name1 error message


Is it possible to insert a ',' between title using sql statement? or do I have to manually fix it?

I would appreciate your help
Reply With Quote
  #4 (permalink)  
Old 12-23-07, 23:50
tiger66 tiger66 is offline
Registered User
 
Join Date: Dec 2007
Posts: 24
Hi
I was able to add ',' to my title
Below the title, there is a line (-------)that's suppose to be under each title. However, because the line does not have ',', one huge long line is below my first title instead of under separate title.

Is there a way to add ',' between those lines or remove the line completely?

Thanks
Reply With Quote
  #5 (permalink)  
Old 12-24-07, 02:41
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 830
Instead of export to excel why don't you import from excel?
Click Data, Import External Data, New Database Query
And select your Sybase ODBC data source
Reply With Quote
  #6 (permalink)  
Old 12-24-07, 04:32
trvishi trvishi is offline
Registered User
 
Join Date: Sep 2003
Location: Switzerland
Posts: 371
Quote:
Originally Posted by tiger66
Hi
I was able to add ',' to my title
Below the title, there is a line (-------)that's suppose to be under each title. However, because the line does not have ',', one huge long line is below my first title instead of under separate title.

Is there a way to add ',' between those lines or remove the line completely?

Thanks

what you can do is omit the header with an isql option -b.

so, in the isql command line. isql -Uuser -X -b

And add an extra select statement in your query to include the header.

select Name1,',',Name2
select col1,',',col2 from table

OR

I have never tried this, try using -s in isql to include colseparator.

i.e.

isql -Uuser -s','

select col1,col2 from table.

Try it and see if that helps. I donno what will happen to the headers when you use -s.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On