0

我的数据如下所示

   Public Name       | Internal Name |
_____________________|_______________|
Name of object1 (#1) |    1345312    |
Name of object2 (#2) |    1387924    | 
..
object2000 (#2000)   |    6875238    |

我希望将 (#*) 解析到它自己的列中。如下所示

Public Number |    Public Name   | Internal Name |
______________|__________________|_______________|
     (#1)     | Name of object1  |    1345312    |
     (#2)     | Name of object2  |    1387924    | 
..
     (#2000)  |    object2000    |    6875238    |

我完全不知道我将如何开始这样做。想法?

4

1 回答 1

1
SELECT 
  [Public Number] = CASE WHEN [Public Name] LIKE '%(#%' THEN
    SUBSTRING([Public Name], CHARINDEX('(', [Public Name]), 255)
    ELSE '' END,
  [New Public Name] = CASE WHEN [Public Name] LIKE '%(#%' THEN
    RTRIM(LEFT([Public Name], CHARINDEX('(', [Public Name])-1))
    ELSE [Public Name] END,
  [Internal Name]
FROM dbo.table;
于 2013-03-28T16:50:42.593 回答