Results 1 to 7 of 7

Thread: OSQL question

  1. #1
    Join Date
    Sep 2003
    Posts
    3

    Angry Unanswered: OSQL question

    Hi I am trying to write a batch file that will give me all records relating to the query.

    osql -S sqlserver -d database -U sa -P "" -Q "select docloc from mhgroup.docmaster where docloc like '%1054193%'"

    The query is truncating the 1054193 to 054193.....

    Is there a problem with using LIKE and the % wildcard in an OSQL statement?

    Thanks,
    Darrin Carter

  2. #2
    Join Date
    Sep 2003
    Posts
    522
    how do you know it's truncating? did you see it in profiler? i just ran it here (slightly modified) and it runs correctly, profiler shows the exact string.

  3. #3
    Join Date
    Sep 2003
    Posts
    3

    Smile

    Originally posted by ms_sql_dba
    how do you know it's truncating? did you see it in profiler? i just ran it here (slightly modified) and it runs correctly, profiler shows the exact string.
    I run it from the batch file that I created. In the DOS window it is missing the 1 at the beginning as well as the % signs


    This is the actual statement:

    osql -S sqlserver -d database -U sa -P "" -Q "select docloc from mhgroup.docmaster where docloc like '%1054193%'"


    This is how it shows up in the DOS window.

    I:\>osql -S sqlserver -d database -U sa -P "" -I -Q "select docloc from mhgroup.docmaster where docloc like 054193"

  4. #4
    Join Date
    Sep 2003
    Posts
    522
    ok, now I get it. %1 is a replacement for the first argument following the batch file name, which is the reason why %1 disappears. I am not sure about the other % sign.

  5. #5
    Join Date
    Sep 2003
    Posts
    522
    you probably will have to use DOS escape codes to make %' visible to OSQL.

  6. #6
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Just use two percent signs (eg : %%) to make one visible to DOS


    eg your actual statement should be :

    osql -S sqlserver -d database -U sa -P "" -Q "select docloc from mhgroup.docmaster where docloc like '%%1054193%%'"

  7. #7
    Join Date
    Sep 2003
    Posts
    3
    Originally posted by Enigma
    Just use two percent signs (eg : %%) to make one visible to DOS


    eg your actual statement should be :

    osql -S sqlserver -d database -U sa -P "" -Q "select docloc from mhgroup.docmaster where docloc like '%%1054193%%'"
    That did it. Thanks!

Posting Permissions

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