1

我有下表:

|  id  |         name            |
----------------------------------
|  1   | 236 SRTD - Something 1  |
----------------------------------
|  2   | 236 SRTD - Something 2  |
----------------------------------
|  3   | 236 SRTD - Something 3  |
----------------------------------
|  4   | 387 SRTD - Something 1  |

从该表中,我想构建另一个类似的视图,但如下所示:

|  id  |  SRTD  |         name            |
-------------------------------------------
|  1   |  236   | 236 SRTD - Something 1  |
-------------------------------------------
|  2   |  236   | 236 SRTD - Something 2  |
-------------------------------------------
|  3   |  236   | 236 SRTD - Something 3  |
-------------------------------------------
|  4   |  387   | 387 SRTD - Something 1  |

如何修改名称列,获取 SRTD 编号,然后创建另一个包含该值的列。

4

1 回答 1

3

对于 SQL Server:

SELECT id, SRTD = SUBSTRING(name, 1, CHARINDEX(' ', name)), name
  FROM dbo.table;
于 2012-07-11T18:49:09.323 回答