Db2
刪除結果集中的撇號
create view ENTRP_SERVS.V_IRS_BULK as Select Atr.Ssn_Tx ,Names.First_Na ,Names.Middle_Na ,Names.Last_Na ,Reff.Ref_Cd_Desc_Tx Suffix_Na ,MBR.PRSN_MBRSH_ID, T_PRSN_MBRSH_TAX.FILTER_TYPE_CD 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_MBRSH_ID Left Outer Join (SELECT (CASE WHEN FILLING_STATUS_CD IN (2061,2062,2063) OR (FILLING_STATUS_CD=2063 AND PRIM_TX_FILER_IN ='Y') THEN 'PRIMARY' WHEN FILLING_STATUS_CD=2063 AND PRIM_TX_FILER_IN ='N' THEN 'SPOUSE' WHEN FILLING_STATUS_CD IN (2066, 2068) THEN 'DEPENDENT' ELSE NULL END) AS FILTER_TYPE_CD,PRSN_MBRSH_ID FROM HIX.T_PRSN_MBRSH_TAX WHERE TAX_FL_YR_NB=YEAR(CURRENT DATE)-2)T_PRSN_MBRSH_TAX ON PE.PRSN_MBRSH_ID=T_PRSN_MBRSH_TAX.PRSN_MBRSH_ID WHERE T_PRSN_MBRSH_TAX.FILTER_TYPE_CD IS NOT NULL
我有這個視圖,我想從 FIRST_NA、MIDDLE_NA 和 LAST_NA 列中刪除撇號 (’)。我怎樣才能做到這一點?
使用該
REPLACE
功能,例如select replace(yourfield,'''','') from yourtable where ...
在這裡,我們將單引號字元替換為空字元串。由於 SQL 字元文字本身包含在單引號中,因此我們通過將單引號字元加倍來轉義文字中的單引號字元。
REPLACE
可以在手冊中找到有關該功能使用的更多資訊,這通常是這種情況。
您如何使用該
replace
函式與char(39)
字元一起執行某些操作,如下例所示:declare @the_string nvarchar(100) = 'His Name is James O''Brian' select @the_string select REPLACE(@the_string, char(39), '')
這將為您提供以下結果: