SELECT [Name]
,[Code]
,case when len([ParentCode]) = '' then [Code] else [ParentCode] end as [ParentCode]
,case when len([Descr])=0 then [Code] else [Descr] end as [Descr]
,[Cumulative]
,[Expense]
,[Accts]
,[Admin]
,[Assessment]
,[Balance]
,[Fiber]
,[GL]
,[LV]
,[Slush]
FROM [KR].[pl].[Accounts]
目前我有那个查询,但我想改变数据包含下划线的部分,而不是在ParentCode和Code列中的空格。例(slush_Code)如何修改此查询以使其工作?
使用replace()
命令:
SELECT REPLACE(ParentCode,'_',' ')
例如:SELECT [Name]
,[Code]
,case
when len([ParentCode]) = 0 then REPLACE(Code,'_',' ')
else REPLACE(ParentCode,'_',' ')
end as [ParentCode]
,case when len([Descr]) = 0 then REPLACE(Code,'_',' ')
else [Descr]
end as [Descr]
,[Cumulative]
,[Expense]
,[Accts]
,[Admin]
,[Assessment]
,[Balance]
,[Fiber]
,[GL]
,[LV]
,[Slush]
FROM [KR].[pl].[Accounts]