SQL script

  • Does anyone know how to get a sql script to run from the cmd line... What i mean by this is that I can type something into the cmd line so that it reaches out and starts the script

  • that really doesnt help me that much... i need to run a command line that will start a query... i have it saved on the c drive of the sql server.

  • Ok, I'm not sure I understand your question. If your attempting to execute a SQL script from the command line, you can use SQLCmd (i.e. calling SQLCmd directly, from a batch file, vbscript, etc.)

    sqlcmd -S

    -or-

    sqlcmd -Q "SELECT * FROM AdventureWorks.Person.Contact" -o MyOutput.txt

  • ok here is the query that i have

    use "washco redtitan"

    Bulk Insert test2

    FROM 'C:\Documents and Settings\test\Desktop\WashingtonXMLScriptssample\washco911.csv'

    WITH

    (

    FirstRow=2,

    FIELDTERMINATOR = '","',

    ROWTERMINATOR = ''

    )

    UPDATE dbo.test2 SET Program = REPLACE(Program, '"', '' )

    update dbo.test2 SET FileName=Replace(FileName, '"','')

    We have a program that creates print files and stores them in a folder. What i need to do is pull the file into sql. The program we are using allows you to create rules or actions when a file is opened. So what I am responsible for is creating something that will pull the data into the sql database. So I wrote this query, and what I need to do is use cmd like to execute this these statements.

  • This sound like a good candiate for SSIS. SQLIS has some good examples, ie.

    http://www.sqlis.com/55.aspx

    What I was suggesting earlier is that you save this query as BLAH.sql and use SQLCmd to execute it. i.e.

    sqlcmd -S MyServer -i C:\MyScript.sql

    SSIS would be a better choice for you given your requirements.

Viewing 6 posts - 1 through 5 (of 5 total)

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