SQL Update和CASE

时间:2014-11-21 03:20:36

标签: sql-server tsql sql-update

我想使用new_BantuanKewanganSTU_TYPC表更新CASE

UPDATE DMSTAG.dbo.TEMP_AKAUN_MARA
SET [new_BantuanKewangan] = [STU_TYPC] 
FROM [SMBM_DBPELJ].[DBPELJ].[MSTUMASTER]
  (CASE
  when [new_BantuanKewangan] = '00' then 'Yes'
  when [new_BantuanKewangan] = '01' then 'No')
  where DMSTAG.dbo.TEMP_AKAUN_MARA.STUDENTN = [SMBM_DBPELJ].[DBPELJ].[MSTUMASTER].STUDENT

错误

  

Msg 102,Level 15,State 1,Line 6
  ')'附近的语法不正确。

1 个答案:

答案 0 :(得分:0)

UPDATE DMSTAG.dbo.TEMP_AKAUN_MARA 
SET DMSTAG.dbo.TEMP_AKAUN_MARA.[new_BantuanKewangan] = 
                       (CASE 
                         WHEN [SMBM_DBPELJ].[DBPELJ].[MSTUMASTER].[STU_TYPC] = '00' THEN 'Yes' 
                         WHEN [SMBM_DBPELJ].[DBPELJ].[MSTUMASTER].[STU_TYPC] = '01' then 'No') 
FROM [SMBM_DBPELJ].[DBPELJ].[MSTUMASTER] 
WHERE DMSTAG.dbo.TEMP_AKAUN_MARA.STUDENTN = [SMBM_DBPELJ].[DBPELJ].[MSTUMASTER].STUDENT