Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2007
    Posts
    32

    Unanswered: 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

  2. #2
    Join Date
    Sep 2003
    Location
    Switzerland
    Posts
    443
    Easy way is to add comma to your sql statement.

    For eg.,

    SELECT col1,',',col2,',',col3 from mytable

  3. #3
    Join Date
    Dec 2007
    Posts
    32
    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

  4. #4
    Join Date
    Dec 2007
    Posts
    32
    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

  5. #5
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    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

  6. #6
    Join Date
    Sep 2003
    Location
    Switzerland
    Posts
    443
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •