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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Sybase query in 1 line of code - possible?

  • 10-07-2013 10:42am
    #1
    Registered Users, Registered Users 2 Posts: 5,658 ✭✭✭


    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, Registered Users 2 Posts: 7,501 ✭✭✭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, Registered Users 2 Posts: 5,658 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 5,658 ✭✭✭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, Registered Users 2 Posts: 576 ✭✭✭ifah


    do it in 2 using :

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


  • Advertisement
  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 5,658 ✭✭✭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, Registered Users 2 Posts: 7,501 ✭✭✭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, Registered Users 2 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,336 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, Registered Users 2 Posts: 4,792 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 5,658 ✭✭✭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