Pipe osql output to a variable

  • HI,

    has anybody an idea how I can pipe the output of an osql-select command within a cmd.file to a variable to react on this variable from within the same cmd-file. I have to start an system-action within a dts-step depending on the result of that select command.

    Many thanks in advance

  • Quite easy. You redirect osql to a file, then you read and parse the content of the file with a FOR /F

    example (to be encoded in mytest.cmd and to be customized for your environment):

    set TEMPFILE=%TEMP%\myprocess%RANDOM%.tmp

    osql -S myserver -E -d mydb -Q "SELECT userid, fullname FROM users" > %TEMPFILE%

    FOR /F "skip=2 tokens=1,*" %%a IN (%TEMPFILE%) DO (

      IF "%%a"=="XYZ" set Fullname=%%b

    )

    IF EXIST %TEMPFILE% del %TEMPFILE%

    Regards

    Luc Bolly


    Kindest Regards,

    Luc Bolly

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply