日期:2014-05-17 浏览次数:20541 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-05-27 20:30:10
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86)
-- Jun 17 2011 00:57:23
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([A] varchar(11))
insert [huang]
select 'G002,350,20' union all
select 'G002,340,32' union all
select 'G005,343,54' union all
select 'G005,343,22' union all
select 'G006,433,55'
--------------开始查询--------------------------
select SUBSTRING(a,1,PATINDEX('%,%',a)-1) [新值]
from [huang]
----------------结果----------------------------
/*
新值
-----------
G002
G002
G005
G005
G006
*/