running sql scripts from command line

  • Hello everyone,

    I am not a sql guru and I need some help.

    I want to query a remote sql2000 database for an entry in a certain table, if the value is there (ex. %computername%) I want to run a script to delete some other entries from another table.....please help ASAP....thank you

  • Viorel,

    Can you please clarify...

    a) do you want to run a script that has all the decision making in it? ie. 1 round trip, where it goes to the server, tests the condition and, if true, does the deletion and returns the results.

    or

    b) do the decision making at your client machine. ie. 2 round trips where script #1 goes to the SQL server and tests the condition, return the test result to your client. Based on that result your client sends script #2 to the SQL server to do the deletion.

    Note: option A is by far the easiest to implement, but please advise which of these you've got in mind.


    Cheers,
    - Mark

  • Mccork,

    I need to take the decision at the client level. Plan "b" is the one I need to be in place.

    Thanks,

    Viorel

  • This example uses osql to test for the author 'White' in pubs, returning zero to the client if there otherwise 1. The && bit tests for zero and executes the osql command to delete.

     
    
    osql -SMyServer -E -Q"exit(select case when exists (select * from pubs..authors where au_lname = 'White') then 0 else 1 end)" && osql -SMyServer -E -Q"delete pubs..sales where qty < 10"


    Cheers,
    - Mark

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

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