Results 1 to 9 of 9

Thread: Syntax for osql for executing sp with parameters.

  1. #1
    Join Date
    Aug 2004
    Location
    USA
    Posts
    80

    Syntax for osql for executing sp with parameters.

    Can anyone tell me syntax for executing a stored procedure using osql which accepts 4 input parameters which are char data types?

    I am getting syntax errors all the time..

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    I believe it should be this:

    osql -Uuserid -Ppassword -Sservername -ddatabase -Q"execute storedprocedure 'parameter1', 'parameter2', 'parameter3', 'parameter4'"

  3. #3
    Join Date
    Feb 2003
    Location
    Indiana USA
    Posts
    1
    osql -U userid -P password -S servername -d database -Q "execute storedprocedure 'parameter1', 'parameter2', 'parameter3', 'parameter4'"

    I think it wants a space

  4. #4
    Join Date
    Dec 2004
    Posts
    502
    It will work the same with or without a space between the switch and the value.

  5. #5
    Join Date
    Aug 2004
    Location
    USA
    Posts
    80
    Thanks, but I am still getting errors:

    Here is the query:

    EXECUTE master..xp_cmdshell 'osql -Sservername -ddbname -Q"exec p_procname '11/03/03','ABX','NPT','KB'" -E'

    Here is the error:

    Server: Msg 170, Level 15, State 1, Line 1
    Line 1: Incorrect syntax near '11'.

    Any idea?

  6. #6
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    EXECUTE master..xp_cmdshell 'osql -SServername -ddbname -Q"exec p_procname ''11/03/03'',''ABX'',''NPT'',''KB''" -E'

  7. #7
    Join Date
    Aug 2004
    Location
    USA
    Posts
    80
    Thanks MAK, but still no luck here..gives me this output:

    usage: osql [-U login id] [-P password]
    [-S server] [-H hostname] [-E trusted connection]
    [-d use database name] [-l login timeout] [-t query timeout]
    [-h headers] [-s colseparator] [-w columnwidth]
    [-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
    [-L list servers] [-c cmdend] [-D ODBC DSN name]
    [-q "cmdline query"] [-Q "cmdline query" and exit]
    [-n remove numbering] [-m errorlevel]
    [-r msgs to stderr] [-V severitylevel]
    [-i inputfile] [-o outputfile]
    [-p print statistics] [-b On error batch abort]
    [-X[1] disable commands [and exit with warning]]
    [-O use Old ISQL behavior disables the following]
    <EOF> batch processing
    Auto console width scaling
    Wide messages
    default errorlevel is -1 vs 1
    [-? show syntax summary]
    NULL

    (19 row(s) affected)

  8. #8
    Join Date
    Sep 2002
    Posts
    5,938
    Did you try run that osql portion in dos prompt?

  9. #9
    Join Date
    Dec 2004
    Posts
    502
    Just to make sure, when using MAK's syntax, did you use 2 consecutive single quotes instead of a double quote when applicable? There should be 2 consecutive single quotes around each parameter. There is a double quote after between -Q and exec, and a double quote before -E. I mean no offense if you indeed read MAK's syntax correctly.

Posting Permissions

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