Stored Proc with Bulk Insert

  • Hi- I have a procedure.

    This procedure have two instructions.

    Each instruction should only be executed one time.

    I receive two messages form query analiser per instruction and i don't know why.

    Can you please Help Me?

    The procedure is this:

    Create proc BULK_INSERT_DATA(@caminho varchar(500))

    as

    execute('BULK INSERT bulk_1

    FROM '''+@caminho+'\1.txt''

    WITH

    (

    FIRSTROW =2,

    FIELDTERMINATOR =''|'',

    ROWTERMINATOR ='''',

    tablock,

    DATAFILETYPE =''widechar''

    )')

    execute ('BULK INSERT bulk_2

    FROM '''+@caminho+'\2.txt''

    WITH

    (

    FIRSTROW =2,

    FIELDTERMINATOR =''|'',

    ROWTERMINATOR ='''',

    tablock,

    DATAFILETYPE =''widechar''

    )')

    go

    The result of the procedure is (when it runs on query analiser) is this:

    (510464 row(s) affected)

    (510464 row(s) affected)

    (53840 row(s) affected)

    (53840 row(s) affected)

    BUT should only be (because i just one that each instruction in the proc, executes one time):

    (510464 row(s) affected)

    (53840 row(s) affected)

    can you please help?

    tks,

    Pedro

  • Stange. Perhaps some batch setting in BULK INSERT

    Print out the commands, and execute them yourself. Do you get the same counts? Each should be executing only once.

  • I now, executed only the folowing comand:

    execute ('BULK INSERT bulk_1

    FROM '''.....1.txt''

    WITH

    (

    FIRSTROW =2,

    FIELDTERMINATOR =''|'',

    ROWTERMINATOR ='''',

    tablock,

    DATAFILETYPE =''widechar''

    )')

    And the result was:

    Result:

    (510464 row(s) affected)

    (510464 row(s) affected)

    if i execute the same comand without the EXECUTE word, the result is this:

    BULK INSERT bulk_1

    FROM '........1.txt'

    WITH

    (

    FIRSTROW =2,

    FIELDTERMINATOR ='|',

    ROWTERMINATOR ='',

    tablock,

    DATAFILETYPE ='widechar'

    )

    Result:

    (510464 row(s) affected)

    It seems like que keyword EXECUTE makes this behavior , does anibody know , why?

    tks,

    Pedro

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

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