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列中的空格。 Ex(slush_Code) 如何修改此查询才能工作?
答案 0 :(得分:6)
基本替换 command
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]