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)
我如何修改此查询才能正常工作?

最佳答案

基本替换 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]

10-01 09:19