日期:2014-05-16 浏览次数:20693 次
----------------------------------------------------------------
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-03-28 07:52:15
-- Version:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
-- Apr 2 2010 15:48:46
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[A]
if object_id('[A]') is not null drop table [A]
go
create table [A]([b] nvarchar(14))
insert [A]
select N'办公室20' union all
select N'党办8' union all
select N'人力资源部13'
--------------生成数据--------------------------
select SUBSTRING(b,1,PATINDEX('%[0-9]%',b)-1)c ,SUBSTRING(b,PATINDEX('%[0-9]%',b),LEN(b))d
from [A]
----------------结果----------------------------
/*
c d
-------------- --------------
办公室 20
党办 8
人力资源部 13
*/