日期:2014-05-18 浏览次数:20374 次
--写个函数试试 GO IF OBJECT_ID('Fun_test')IS NOT NULL DROP FUNCTION Fun_test GO CREATE FUNCTION Fun_test(@name varchar(20)) RETURNS VARCHAR(20) AS BEGIN --IF CHARINDEX(' ',@name)>0 --begin declare @str varchar(20) set @str='' declare @firstname varchar(10) declare @midname varchar(10) declare @lastname varchar(10) select @firstname=(left(@name,charindex(' ',@name)-1)) select @midname=(substring(@name,charindex(' ',@name)+1,charindex(' ',@name,charindex(' ',@name)))) select @lastname=reverse(left(reverse(@name),len(@name)-3-charindex(' ',@name,charindex(' ',@name)))) select @str=@lastname+' '+left(@firstname,1)+'.'+left(@midname,1) return @str --end END go GO CREATE TABLE #TEST( NAME VARCHAR(20) ) INSERT #TEST SELECT 'Chen Xi Ou Yang' UNION ALL SELECT 'Chun Xia Song' SELECT dbo.Fun_test(NAME) AS NEMAE FROM #TEST /* NEMAE Ou Yang C.X Song C.X */