| |
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.
|
 |

12-22-07, 02:03
|
|
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
|
|

12-22-07, 08:11
|
|
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
|
|

12-23-07, 23:09
|
|
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
|
|

12-23-07, 23:50
|
|
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
|
|

12-24-07, 02:41
|
|
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
|
|

12-24-07, 04:32
|
|
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.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|