【问题标题】:How to inserted a computed column如何插入计算列
【发布时间】:2017-10-18 19:48:40
【问题描述】:

我正在尝试使用来自多重连接表的值插入到一个表中。

这是我的代码:

    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?

【问题讨论】:

  • 计算列的重点在于您没有在insert 中设置值。

标签: sql


【解决方案1】:

您不能将值插入计算列,但您可以这样做:

sql insert into a table with computed columns

【讨论】:

    猜你喜欢
    • 2022-10-13
    • 1970-01-01
    • 2011-09-15
    • 2021-08-08
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多