Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2010
    Posts
    4

    Question Unanswered: How to write a Query in bcp command in UNIX

    Hi Guys,

    Can you please tell me how to insert a Sybase query into bcp command in UNIX in-order to insert the data from query result into a temp file.... thanks for your help in advance.

    -----Aditya

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    You can't. Create a view then bcp out the view.

  3. #3
    Join Date
    Feb 2010
    Posts
    4
    I have exactly one field in the temporary file and also have exactly one field in the temporary table in the database, could you please tell how do i get that data present in the file into the table using bcp command

  4. #4
    Join Date
    Jan 2004
    Posts
    545
    Provided Answers: 4
    Look up the syntax of the bcp-command in de online documentation. Use it to bcp-out the table. If you want the data in a specific order, create a view on the table with an order by-clause and bcp-out the view insted of the table.
    I'm not crazy, I'm an aeroplane!

  5. #5
    Join Date
    Feb 2010
    Posts
    4
    Thanks for your reply

  6. #6
    Join Date
    Feb 2010
    Posts
    4

    Question

    Can we set a value of the variable of Unix in Sybase programming in Unix Shell Scripting ??

    I mean like below code :

    #!/bin/ksh
    export x
    isql -Uusername -Ppassword -Sserver <<-EOF
    x=0
    EOF

  7. #7
    Join Date
    Jan 2004
    Posts
    545
    Provided Answers: 4
    As far as I know that is not possible. It is possible to use an sql-script as input for ISQL (with the -i parameter). If you generate that script on the fly, it is possible to use variables in it.
    I'm not crazy, I'm an aeroplane!

  8. #8
    Join Date
    Feb 2009
    Location
    Prague
    Posts
    17
    chaditya:

    Of course, possiblities are unlimited in shell :-)
    If you export external variables, you can use them in script like the following one.

    #!/usr/bin/sh

    db1=testdb
    table1=aaa
    val1=bbb
    pwd=pwd

    isq -Usa -S ASE <<-EOF
    ${pwd}
    use ${db1}
    go
    select * from ${table1} where col1=${val1}
    go
    exit
    EOF


    you can also get the output into variable:

    #!/usr/bin/sh

    db1=testdb
    table1=aaa
    val1=bbb
    pwd=pwd

    result=`isq -Usa -S ASE <<-EOF | grep -vE '\-\-\-\-|name'
    ${pwd}
    use ${db1}
    go
    select * from ${table1} where col1=${val1}
    go
    exit
    EOF`

    echo $result



    etc...

Posting Permissions

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