Home Forums SQL Server 2005 T-SQL (SS2K5) I am trying to find the record that already exists, and I get the Msg 128, Level 15, State 1 error. RE: I am trying to find the record that already exists, and I get the Msg 128, Level 15, State 1 error.

  • your error is your print statement, you cannot print a column's value.

    PRINT 'Record already exists in mbrship table' + mbrs_id

    you have to print something static or a variable like @mbrs_id that you'd need to declare and populate.

    it also looks like you might exclude a other inserts because at least one row has a match in temp.

    i would join temp tot eh table and only insert items that did not exist, like this:

    INSERT INTO Mbrship(...)

    SELECT (...)

    FROM temp_Mbrship tm

    [highlight="#ffff11"] LEFT JOIN mbrship m

    ON tm.mbrs_id = m.mbrs_id[/highlight]

    WHERE tm.mbrs_id IN ( '00040687', '00001010', '00002120', '00002640',

    '00022121', '00032690', '00037870', '00041367',

    '00046090', '00050060', '00041760', '00043970',

    '00065860', '00066331', '00085100' )

    [highlight="#ffff11"]AND m.mbrs_id IS NULL [/highlight]

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!