Looping through files(.txt) in the directory using sqlserver 2005(Very Urgent).

  • Hi,

    Can any one please tell me how do I loop through the folder that has .txt files using SQLserver2005 and select the latest file and update the content of the file in the table using a stored procedure.

    Please find the stored procedure that would help me update the content of the file into the table.

    Create Proc upLoadFile (@tableName varchar(50),

    @primaryColName varchar(50),

    @primaryColValue int,

    @blobColName varchar(50),

    @fileName varchar(200))

    as

    begin

    declare @tsql varchar(400)

    set nocount on

    set @tsql = 'UPDATE ' + @tableName + ' SET ' + @blobColName + ' = ' +

    '(SELECT * from OPENROWSET(BULK N' + '''' + @fileName + '''' +

    ',SINGLE_BLOB) as blob )' + ' WHERE ' + @primaryColName +

    ' = ' + convert (varchar(20),@primaryColValue)

    --print (@tsql)

    EXEC (@tsql)

    set nocount off

    end

    GO

  • Are you trying to do this just using TSQL?

    IMHO, this is a task better done through SSIS with a file system task or a script task.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

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

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