Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    1

    Unanswered: SQL server 2005 - command line argument

    Hi,
    I am trying to execute an sql script file from command prompt like,

    c:\> "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.EXE" -E -S (local) -d master -i "d:\sample\bulk.sql"

    bulk.sql script file content is,

    USE [myDatabase]
    GO
    DECLARE @Path NVARCHAR(1000)
    --Step 1: Build Valid BULK INSERT Statement
    DECLARE @SQL varchar(2000)
    SET @SQL = 'BULK INSERT abc FROM '+@Path+' WITH (FIELDTERMINATOR = '','',ROWTERMINATOR = ''\n'')'
    --Step 2: Execute BULK INSERT statement
    EXEC (@SQL)

    Now for the above bulk.sql script I need to pass Path="D:\sample\test.txt" as command line argument.
    How to do that, friends can anybody help me?.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    What about the -v parameter as documented in the manual?

    http://msdn.microsoft.com/en-us/library/ms162773%28SQL.90%29.aspx

    You can use variables defined that way as ${varname} inside your sql script.

  3. #3
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Quote Originally Posted by shammat
    ...You can use variables defined that way as ${varname} inside your sql script.
    I think you meant $(varname)
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  4. #4
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by rdjabarov
    I think you meant $(varname)
    Ah, right. Sorry for the confusion

Posting Permissions

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