SQL自定义列基于其他列

时间:2016-09-16 15:37:33

标签: sql ms-access

如何基于另外两列创建自定义列。 这是我试过但我得到一个错误。

SELECT data_tbl.start_date as [Date], 
       data_tbl.start_time as [Time], 
       data_tbl.job as [Job Number], 
       data_tbl.part as [Part Number],
       workType as CASE
                    WHEN data_tbl.is_setup='Yes' THEN 'Setup'
                    WHEN data_tbl.is_production='Yes' THEN 'Production'
FROM data_tbl

'workType'是我的自定义列,我想根据'is_setup'和'is_production'字段(是/否字段)填充iether“setup”或“production”。

我使用MS-Access

错误消息: Select语句包含拼写错误或缺失的保留字或参数名称,或标点符号不正确

1 个答案:

答案 0 :(得分:0)

SELECT data_tbl.start_date as [Date], 
       data_tbl.start_time as [Time], 
       data_tbl.job as [Job Number], 
       data_tbl.part as [Part Number],
       IIF(data_tbl.is_setup='Yes', 'Setup',
           IIF(data_tbl.is_production='Yes', 'Production', '')
           ) as workType

FROM data_tbl