2017-10-18 65 views
0

我試圖插入到乘法連接表中的值的表中。如何插入一個計算列

這裏是我的代碼:

INSERT INTO [dbo].[ORD_PURCHASING_GROUP_DTL] 
       ([ORG_ID] 
       ,[ORG_UNIT_ID] 
       ,[PURCHASING_GROUP] 
       ,[MASTER_CUSTOMER_ID] 
       ,[SUB_CUSTOMER_ID] 
       ,[ADDOPER] 
       ,[ADDDATE] 
       ,[MODOPER] 
       ,[MODDATE] 
       ,[CONCURRENCY_ID] 
       ,[EFFECTIVE_BEGIN_DATE] 
       ,[EFFECTIVE_END_DATE] 
       ,[LAST_FIRST_NAME] 
       ,[ACTIVE_FLAG] 
      ) 
    (select 'SIAM', 'SIAM', CONCAT(@conf_name, '-', demo.DEMOGRAPHIC_CODE) 
as PURCHASING_GROUP, demo.master_customer_id, 0, 'SIAM_MTG_PG_SQL' as 
ADDOPER, GETDATE() as ADDDATE, NULL as MODOPER, NULL as MODDATE, 0, 
demo.USER_D1 as EFFECTIVE_BEGIN_DATE, NULL as EFFECT_END_DATE, 
cus_addr.Last_First_Name as LAST_FIRST_NAME , cus_status.ACTIVE_FLAG as 
ACTIVE_FLAG 
    from cus_demographic as demo 
     join CUS_PRIMARY_EMPL_ADDR_MBR_VW cus_addr on 
demo.MASTER_CUSTOMER_ID = cus_addr.MASTER_CUSTOMER_ID 
     join CUS_STATUS_VW cus_status on demo.MASTER_CUSTOMER_ID = 
cus_status.MASTER_CUSTOMER_ID 
     where 
      1 = 1 
     and demographic_code in (
      select RIGHT(pg.PURCHASING_GROUP, LEN(pg.PURCHASING_GROUP)- 
CHARINDEX('-', pg.PURCHASING_GROUP)) 
      FROM [ORD_PURCHASING_GROUP] as pg 
       where pg.PURCHASING_GROUP like concat(@conf_name, '%') 
     ) 
     and demographic_subcode = @conf_name) 

我得到的錯誤:

Msg 271, Level 16, State 1, Line 82 
The column "LAST_FIRST_NAME" cannot be modified because it is either a 
computed column or is the result of a UNION operator. 
Msg 271, Level 16, State 1, Line 82 
The column "ACTIVE_FLAG" cannot be modified because it is either a computed 
column or is the result of a UNION operator. 

我不知道如何插入 「計算列」。我說一個帖子說它應該改變桌子。但我想插入這些值...

這裏是鏈接... How do you add a computed column to a Table?

+3

全一個計算列的點是你不在'insert'中設置值。 –

回答