日期:2014-05-17 浏览次数:20429 次
----------------------------
-- Author :fredrickhu(小F,向高手学习)
-- Date :2011-04-25 16:27:38
-- Verstion:
-- Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
-- Jul 9 2008 14:43:34
-- Copyright (c) 1988-2008 Microsoft Corporation
-- Enterprise Evaluation Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)
--
----------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([序号] int,[性别] varchar(2),[名字] varchar(60))
insert [tb]
select 1,'男','LeBron Raymone James' union all
select 2,'男','Dwyane Wade James Jack' union all
select 3,'女','LeBron Raymone Jack'
--------------开始查询--------------------------
select
序号,
性别,
reverse(PARSENAME(replace(reverse(名字),' ','.'),1))+' '+reverse(PARSENAME(replace(reverse(名字),' ','.'),2))
from
tb
----------------结果----------------------------
/* 序号 性别
----------- ---- ----------------------------------------------------------------------------------------------------------------
1 男 LeBron Raymone
2 男 Dwyane Wade
3 女 LeBron Raymone
*/