Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Sybase query in 1 line of code - possible?

Options
  • 10-07-2013 11:42am
    #1
    Registered Users Posts: 5,531 ✭✭✭


    Hi folks

    Im doing the following Sybase query

    isql -Usa -Psybase11
    Use someDB
    go
    Select count(*) from SomeTable where Something=something
    go
    exit



    I want to put this into a 1 lines command (not scripted please, just a command).

    Is this possible?


Comments

  • Registered Users Posts: 7,500 ✭✭✭BrokenArrows


    I assume you mean a command line command??

    If that's the case just put your script into a batch file and call the batch file

    edit: alternatively put the SQL bit into a .sql file and pass the .sql file in as a parameter to the isql.exe


  • Registered Users Posts: 5,531 ✭✭✭veryangryman


    I assume you mean a command line command??

    If that's the case just put your script into a batch file and call the batch file

    edit: alternatively put the SQL bit into a .sql file and pass the .sql file in as a parameter to the isql.exe

    Thanks but lets assume i cant use a file - the creation of the file is kinda another command.

    Any other suggestions to do in 1 line


  • Registered Users Posts: 2,021 ✭✭✭ChRoMe


    Thanks but lets assume i cant use a file - the creation of the file is kinda another command.

    Any other suggestions to do in 1 line

    It would be helpful to describe your constraints in more detail.


  • Registered Users Posts: 5,531 ✭✭✭veryangryman


    ChRoMe wrote: »
    It would be helpful to describe your constraints in more detail.

    My first post shows exactly what is needed to do. It does it in 4 lines though, im wondering if its possible to do in 1


  • Registered Users Posts: 576 ✭✭✭ifah


    do it in 2 using :

    Select count(*) from SomeDB..SomeTable where Something=something
    go


  • Advertisement
  • Registered Users Posts: 2,021 ✭✭✭ChRoMe


    My first post shows exactly what is needed to do. It does it in 4 lines though, im wondering if its possible to do in 1

    They are not your constraints, they are your goals.

    Ambiguous descriptions of the problem space such as "Thanks but lets assume i cant use a file - the creation of the file is kinda another command. " make it more difficult for people to provide possible solutions.


  • Registered Users Posts: 5,531 ✭✭✭veryangryman


    ChRoMe wrote: »
    They are not your constraints, they are your goals.

    Ambiguous descriptions of the problem space such as "Thanks but lets assume i cant use a file - the creation of the file is kinda another command. " make it more difficult for people to provide possible solutions.

    My constraints then are the fact that i need to do it in 1 line of bash shell code. No sql prompts etc, just a 1 line bash command.


  • Registered Users Posts: 7,500 ✭✭✭BrokenArrows


    isql.exe doesn't have any parameters to pass SQL via the command line.
    As I said you can pass in a file name containing the SQL but that requires you to create a file which you said you cannot do.

    So the answer is NO. You cannot do what you ask.


  • Registered Users Posts: 1,456 ✭✭✭FSL


    you could using osql on a MS-SQL server as it has a -q parameter i.e. -q "query text"


  • Moderators, Technology & Internet Moderators Posts: 1,333 Mod ✭✭✭✭croo


    I don't know anything about Sybase but have you tried just echo-ing the db commands and pipe that through to isql? Something along the lines of ...
    echo "Select count(*) from SomeTable where Something=something" | isql -Usa -Psybase11 -DsomeDB


  • Advertisement
  • Registered Users Posts: 4,757 ✭✭✭cython


    croo wrote: »
    I don't know anything about Sybase but have you tried just echo-ing the db commands and pipe that through to isql? Something along the lines of ...

    I'm going to have to admit the same here, but the below is derived from a solution I have used for Oracle for various things in the past. It's not technically a one liner, but it may well be the closest you're going to get:
    isql -Usa -Psybase11  <<ENDOFSQL
    Use someDB
    go
    Select count(*) from SomeTable where Something=something
    go
    exit
    ENDOFSQL
    

    As already noted though, the question is why do you need to do this? For one thing you're executing multiple commands in Sybase, but yet want them in one line in bash (odd, and potentially straightforward). In a more general sense though, you are presumably not looking for this for interactive use, as it would just be easier to access via the intended prompt, but yet you say it's not to be scripted - simply put, why are you trying to do this in this manner, and what are you hoping to achieve?


  • Registered Users Posts: 1,311 ✭✭✭Procasinator


    You could probably just use something like this:
    printf "Use someDB\ngo\nSelect count(*) from SomeTable where Something=something\ngo\nexit" | isql -Usa -Psybase11
    


  • Registered Users Posts: 5,531 ✭✭✭veryangryman


    You could probably just use something like this:
    printf "Use someDB\ngo\nSelect count(*) from SomeTable where Something=something\ngo\nexit" | isql -Usa -Psybase11
    

    You my friend, are a legend.

    Thanks to all who contributed, this solves my problem!


Advertisement