我有一个视图,要从其中删除一列中的特定字符。具体来说就是下面“资金”列中的字符“ B”。
我尝试使用以下版本的TRIM
SELECT
TRIM('B' FROM [Port_Ticker]) as "Fund"
,[BENCH_Ticker] as "Index ID"
,format(cast([VALUE_DATE] as Date),'dd/MM/yyyy') as "Updat"
,([Port_Risk_Contrib] / 10000000) as "StDev Fund"
,([Active_risk_contrib] / 10000000) as "TE"
,([BENCH_RISK_CONTRIB] / 100) as "StDev BM"
FROM [DM_PORTFOLIO_ANALYSIS].[basedata].[PortfolioRiskFigures]
where [BLOCK_FACTOR] = 'Total'
and [Port_ticker] =
'B1023'
order by [VALUE_DATE] asc
哪个给我错误
第156条消息,第15级,状态1,第3行。 关键字“ FROM”附近的语法不正确。
答案 0 :(得分:3)
您可以使用replace()
来执行此操作。在这种情况下,它将搜索'B'
并将其替换为空字符串-> ''
。请注意,此功能将替换此列中的所有'B'
。
SELECT
REPLACE([Port_Ticker], 'B', '') as "Fund"
,[BENCH_Ticker] as "Index ID"
,format(cast([VALUE_DATE] as Date),'dd/MM/yyyy') as "Updat"
,([Port_Risk_Contrib] / 10000000) as "StDev Fund"
,([Active_risk_contrib] / 10000000) as "TE"
,([BENCH_RISK_CONTRIB] / 100) as "StDev BM"
FROM [DM_PORTFOLIO_ANALYSIS].[basedata].[PortfolioRiskFigures]
where [BLOCK_FACTOR] = 'Total'
and [Port_ticker] = 'B1023'
order by [VALUE_DATE] asc
答案 1 :(得分:3)