Passing a file path to a SP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maury

    Passing a file path to a SP

    I'm trying to write a SP that
    accept in input a parameter with the name
    of a file (with complete path)
    but I noticed some problems....

    It's right this way? Thanks!

    set ANSI_NULLS ON
    set QUOTED_IDENTIFI ER ON
    go

    ALTER PROCEDURE [dbo].[BI]
    @FileToImport nvarchar(100)
    AS
    BEGIN
    SET NOCOUNT ON;
    DECLARE @SQL nvarchar(200)

    SET @SQL = "BULK INSERT tmptable FROM '"+@FileToImpor t+"'"
    EXEC (@SQL)
    END
  • Dan Guzman

    #2
    Re: Passing a file path to a SP

    Try enclosing the literal in single-quotes. Specify 2 single-quotes inside
    the literal where you have an embedded single-quote:

    SET @SQL = 'BULK INSERT tmptable FROM '''+@FileToImpo rt+''''

    --
    Hope this helps.

    Dan Guzman
    SQL Server MVP

    "Maury" <maurizio.alber ti_TOGLI_@gmail .com> wrote in message
    news:qS7Yf.6484 3$A83.1587071@t wister1.libero. it...[color=blue]
    > I'm trying to write a SP that
    > accept in input a parameter with the name
    > of a file (with complete path)
    > but I noticed some problems....
    >
    > It's right this way? Thanks!
    >
    > set ANSI_NULLS ON
    > set QUOTED_IDENTIFI ER ON
    > go
    >
    > ALTER PROCEDURE [dbo].[BI]
    > @FileToImport nvarchar(100)
    > AS
    > BEGIN
    > SET NOCOUNT ON;
    > DECLARE @SQL nvarchar(200)
    >
    > SET @SQL = "BULK INSERT tmptable FROM '"+@FileToImpor t+"'"
    > EXEC (@SQL)
    > END[/color]


    Comment

    • Maury

      #3
      Re: Passing a file path to a SP

      Dan Guzman ha scritto:[color=blue]
      > Try enclosing the literal in single-quotes. Specify 2 single-quotes inside
      > the literal where you have an embedded single-quote:
      >
      > SET @SQL = 'BULK INSERT tmptable FROM '''+@FileToImpo rt+''''
      >[/color]
      IT'S OK!!!!
      Thank you very very much.....
      (and sorry I'm a newbie in SQL Server)

      Comment

      Working...