problem with if statement

  • hi all,

    i am trying to update tables based on value of @tablename variable

    but i am getting the following error

    my query is

    if(@tablename='tbl_client')

    begin

    SELECT @TABLENAME

    select * from #tbl_temp

    update tbl_client set attrib_value=b.attrib_value,attrib_uom=b.attrib_uom from tbl_client a inner join #tbl_temp b on a.id=b.id

    end

    if(@tablename='tbl_stdclient')

    begin

    select * from #tbl_temp

    SELECT @TABLENAME

    update tbl_stdclient set stdattrib_value=b.stdattrib_value from tbl_stdclient a inner join #tbl_temp b on a.id=b.id

    end

    if(@tablename='tbl_nmpair')

    begin

    select * from #tbl_temp

    SELECT @TABLENAME

    update tbl_nmpair set plntno=b.plntno,batchno=b.batchno from tbl_nmpair a inner join #tbl_temp b on a.id=b.id

    end

    i am getting the following error

    Server: Msg 207, Level 16, State 1, Procedure usp_tlfproc, Line 60

    Invalid column name 'stdattrib_value'.

    Invalid column name 'plntno'.

    Server: Msg 207, Level 16, State 1, Procedure usp_tlfproc, Line 66

    Invalid column name 'batchno'.

    Server: Msg 207, Level 16, State 1, Procedure usp_tlfproc, Line 66

  • Can you Post the complete query ?

    karthik

  • Hello,

    I would expect this kind of error message if the referenced columns do not exist in the tables.

    In particular check the (permanent) table "tbl_stdclient" - Is there definitely a column named "stdattrib_value"? If so, are you using a case sensitive collation, or are there multiple "tbl_stdclient" tables within different schemas?

    Regards,

    John Marsh

    www.sql.lu
    SQL Server Luxembourg User Group

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

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