在下面的视图中,我想添加一个名为“ABC”的列(不改变视图),它以格式显示日期YYYYMM
(没有日期,只有年份和月份)。我怎样才能做到这一点?我正在使用 db2。
create view VIEW_IRS1 as Select
MBR.PRSN_MBRSH_ID
, Atr.Ssn_Tx
, Names.First_Na
, Names.Middle_Na
, Names.Last_Na
, Reff.Ref_Cd_Desc_Tx Suffix_Na
,'FALSE' AS "Request Title II Monthly Income Verification"
From Hix.T_Enrt En
Inner Join Hix.T_Prsn_Enrt Pe On En.Enrt_Id = Pe.Enrt_Id And En.Enrt_Status_Cd In
(428,439, 430 ) And Pe.Active_In = 'Y' And (Pe.Retro_In Is Null Or Pe.Retro_In = 'N')
Left Outer Join Hix.T_Aptc Ap On En.Enrt_Id = Ap.Enrt_Id
Left Outer Join Hix.T_Prsn_Addl_Attr Atr On Pe.Prsn_Mbrsh_Id = Atr.Prsn_Mbrsh_Id
Left Outer Join
(
Select nAc.Prsn_mbrsh_Id, First_Na , Middle_Na , Last_Na, Suffix_Cd From
Hix.T_Prsn_Name Na, Hix.t_prsn_mbrsh_prsn_name_ac nAc
where na.prsn_name_id = nAc.prsn_Name_Id
) Names On Pe.prsn_mbrsh_id = Names.prsn_mbrsh_id
Left Outer Join Hix.T_Ref_Data Reff On Names.Suffix_Cd = Reff.Ref_Data_Id
Left Outer Join Hix.T_Ref_Data Re On Atr.GENDER_CD = Reff.Ref_Data_Id
Left Outer Join Hix.T_PRSN_MBRSH MBR on MBR.PRSN_MBRSH_ID=Pe.PRSN_ENRT_ID;
(这里假设 DB2 for Linux/Unix/Windows,因为您没有指定,但这可能也适用于其他平台。)
您不必做时髦的日期数学运算,有一个内置函数
VARCHAR_FORMAT
可以为您完成: