• rhd110 (3/1/2012)


    Hi,

    Using the command prompt we use

    1. Open Run window

    2. Type SQLCMD enter

    3. Type USE TestDB enter

    4. Type GO enter

    5. EXEC dbo.sp_InsertTempValue 101

    6. Type GO enter

    The following steps insert values 101 in a certain table

    How can we do using MASTER..XP_CMDSHELL

    Following are the steps I have tried

    EXEC MASTER..XP_CMDSHELL 'SQLCMD'

    EXEC MASTER..XP_CMDSHELL 'USE TOOLDB'

    EXEC MASTER..XP_CMDSHELL 'GO'

    EXEC MASTER..XP_CMDSHELL 'EXEC dbo.InsertTempValue 10'

    EXEC MASTER..XP_CMDSHELL 'GO'

    But this doesn't execute

    Any other method to achieve this

    I wouldn't. Just open a session and typw the SQL. xp_cmdshell is used in SQL to run command line statements that cannot be run in SQL. Why would you use SQL to send SQL to command line?

    Jared
    CE - Microsoft