The multi-part identifier "stgCustPmt.TranCmnt" could not be bound

  • I have the following code that is part of a larger script that runs against several tables cleaning data.

    declare @oldcomment varchar;

    declare @newcomment varchar;

    if stgCustPmt.TranCmnt is not null

    begin

    set @oldcomment = stgCustPmt.TranCmnt;

    set @newcomment = 'OldPmtNo: ' + cast(stgCustPmt.TranCmnt as varchar) + ' Cmt: ' + @oldcomment;

    update stgCustPmt

    set TranCmnt = @newcomment;

    end

    else

    begin

    set @newcomment = 'OldPmtNo: ' + cast(stgCustPmt.TranCmnt as varchar)

    update stgCustPmt

    set TranCmnt = @newcomment;

    end

    when I run this code segment, I get the error. any help would be appreciated. I get the error for each of the table.column entries.

  • You can't reference a column in a table without a select, update, or delete FROM table. You are saying:

    IF table.column then

    And SQL Server has no idea what table.column is. You need to create a variable that holds the column and do a:

    Select @column = column from table

    Then you do:

    If @column = x

  • Ok, that at least got me past my errors, now working out the logic.

    Thanks.

    Phillip

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

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