Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2008
    Posts
    7

    Unanswered: osql in a batch file

    Hi,

    I have to do a sql query to show me a data in a batch file, but I don't know how pass it a parameter:

    Conexion:
    osql -U sa -P pass -S xxx.xx.x.xx,2000 -i query

    query:

    select DATA_CENTER, SCHED_TABLE, convert(char(16),NODE_ID) AS "MAQUINA",MEMNAME, convert(char(13),JOB_NAME) AS "JOB_NAME", convert(char(10
    ),OWNER)"OWNER", convert(char(6),substring(GROUP_NAME,9,14))"GRUPO" , convert(char(2),CONFIRM_FLAG)"C?", convert(char(1),DESCRIPTION)
    AS "D", convert(char(3),MAX_WAIT)"MXW"
    from em620.dbo.DEF_JOB J, em620.dbo.DEF_TABLES T where T.TABLE_ID = J.TABLE_ID and J.MEMNAME like (HERE GOES THE PARAMETER)


    That I would like to do it's from command-line execute:

    prueba.bat losestados.sh

    And "losestados.sh" will be the parameter of the sql.

    Could you say me how could I do?

    Many thanks and sorry for my english!

  2. #2
    Join Date
    May 2004
    Location
    Seattle
    Posts
    1,313
    Can you use sqlcmd instead? with sqlcmd you can pass parameters with -v switch

    osql does not support this though. with osql, you could do this in your .bat file:

    set MYPARAM=%1
    set sql=select * from foo where mycol like '%MYPARAM%'
    call osql -Q "%sql%" -SMYSERVER -dMYDATABASE

  3. #3
    Join Date
    Dec 2008
    Posts
    7
    I try to do this but doesn't work


    C:\Documents and Settings\admibm>osql -U sa -P admindba -S 172.23.3.73,2000 -Q "
    select DATA_CENTER, SCHED_TABLE,convert(char(16),NODE_ID) AS "MAQUINA",MEMNAME,c
    onvert(char(13),JOB_NAME) AS "JOB_NAME",convert(char(10),OWNER)"OWNER", convert(
    char(6),substring(GROUP_NAME,9,14))"GRUPO", convert(char(2),CONFIRM_FLAG)"C?",co
    nvert(char(1),DESCRIPTION) AS "D", convert(char(3),MAX_WAIT)"MXW" from em620.dbo
    .DEF_JOB J, em620.dbo.DEF_TABLES T where T.TABLE_ID = J.TABLE_ID and J.MEMNAME l
    ike 'FM001DIE.sh'"
    COUNT field incorrect or syntax error

    C:\Documents and Settings\admibm>osql -U sa -P admindba -S 172.23.3.73,2000
    1> select DATA_CENTER, SCHED_TABLE,convert(char(16),NODE_ID) AS "MAQUINA",MEMNAM
    E,convert(char(13),JOB_NAME) AS "JOB_NAME",convert(char(10),OWNER)"OWNER", conve
    rt(char(6),substring(GROUP_NAME,9,14))"GRUPO", convert(char(2),CONFIRM_FLAG)"C?"
    ,convert(char(1),DESCRIPTION) AS "D", convert(char(3),MAX_WAIT)"MXW" from em620.
    dbo.DEF_JOB J, em620.dbo.DEF_TABLES T where T.TABLE_ID = J.TABLE_ID and J.MEMNAM
    E like 'FM001DIE.sh'
    2> GO
    DATA_CENTER SCHED_TABLE MAQUINA
    MEMNAME JOB_NAME OWNER GRUPO C? D

    MXW
    -------------------- -------------------- ----------------
    ------------------------------ ------------- ---------- ------ ---- ----

    ----
    CPDV FM-dia-contab-cert ccsol126
    FM001DIE.sh FM001DIE fmuser imple- 1 i

    0
    CPDV FM-dia-contab FM
    FM001DIE.sh FM001DIE fmuser imple- 0 i

    1
    CPDV FM-dia-info FM
    FM001DIE.sh FM001DIE fmuser imple- 0 E

    1
    CPDV FM-dia-info-cert ccsol126
    FM001DIE.sh FM001DIE fmuser imple- 1 E

    0

    (4 rows affected)
    1>

    Any help?? Many thanks!

  4. #4
    Join Date
    Aug 2008
    Location
    India
    Posts
    55
    Copy and paste the select query in test.sql and place in it required drive say C: drive and use the following command

    osql -Usa -Ppass -Sxxx.xx.x.xx,2000 -iC:\test.sql -oc:\test_out.txt

  5. #5
    Join Date
    Aug 2008
    Location
    India
    Posts
    55
    Output will be available in c:\test_out.txt

Posting Permissions

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