日期:2014-05-17 浏览次数:20696 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-03-14 11:53:33
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
-- Jun 17 2011 00:54:03
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1, v.721)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([id] int,[tel] varchar(9),[mobie] sql_variant)
insert [huang]
select 1,'1234,5678',null union all
select 2,'3455,6666',null
--------------开始查询--------------------------
select id,SUBSTRING(tel,1,PATINDEX('%,%',tel)-1)[tel], SUBSTRING(tel,PATINDEX('%,%',tel)+1,LEN(tel)+1-PATINDEX('%,%',tel))[mobie]
from [huang]
----------------结果----------------------------
/*
id tel mobie
----------- --------- ---------
1 1234 5678
2 3455 6666
(2 行受影响)
*/