Row Select and XP_CMDSHELL Execution?

  • Hi All,

    Wally the struggling DBA one again... 🙂

    I am looking for a simple way to query a table for row count, and if there are any rows in the table (indicating a backup of the application) we want to execute a batch script on the server via XP_CMDSHELL to deal with some flaky services.

    What type of logic will work when rowcount > 0 to do this?

    Thanks in advance for your guidance!

    Wally

    [font="Verdana"]-- Wally
    -- Reluctant DBA[/font]

  • Well, to check for a table's rowcount being > 0, I would try this:

    if exists (select 1 from table)

    execute master..xp_cmdshell ...

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Thanks Wayne - I think that will do it!

    [font="Verdana"]-- Wally
    -- Reluctant DBA[/font]

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

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