UDF—SQL Server 2000的新特性
2005-11-06 17:02:01 来源:WEB开发网核心提示: CREATE FUNCTION dbo.Capitalize ( -- Capitalize the first character of every word, -- sentence, or the whole string. Put the rest to lowercase. @String VARCHAR
CREATE FUNCTION dbo.Capitalize (
-- Capitalize the first character of every word,
-- sentence, or the whole string. Put the rest to lowercase.
@String VARCHAR (8000),
@Capitalize_What VARCHAR (8) = ’string’
-- String: Capitalize the first letter of the string
-- Sentence: Capitalize the first letter of every sentence.
-- Delimiters: ./!/?
-- Word: Capitalize the first letter of every word.
-- Delimiters: any characters other than letters and digits.
)
RETURNS VARCHAR(8000)
AS
BEGIN
DECLARE @Position SMALLINT,
@Char CHAR(1),
@First_Char CHAR (1),
@Word_Start SMALLINT
SET @Capitalize_What = LOWER( @Capitalize_What )
SET @Word_Start = 0
IF @Capitalize_What IN (‘word’, ‘sentence’)
BEGIN
SET @Position = DATALENGTH( @String )
WHILE @Position >= 0 BEGIN
SET @Char = CASE @Position
WHEN 0 THEN ’.’
ELSE UPPER( SUBSTRING(
@String, @Position,
1 ) )
END
IF @Char BETWEEN ’A’ AND ’Z’
OR @Char BETWEEN ’0’ and ’9’ BEGIN
SET @Word_Start = @Position
SET @First_Char = UPPER( @Char )
END
ELSE BEGIN
IF @Capitalize_What = ’word’
OR @Char in ( ’.’, ’!’, ’?’ ) BEGIN
IF @Word_Start > 0
AND @First_Char BETWEEN ’A’
AND ’Z’
SET @String = STUFF(
@String, @Word_Start,
1, @First_Char )
SET @Word_Start = 0
END
END
SET @Position = @Position - 1
END
END
ELSE BEGIN -- Capitalize the first character
SET @Position = 0
WHILE @Position < DATALENGTH( @String )
BEGIN
SET @Position = @Position + 1
SET @Char = UPPER( SUBSTRING( @String,
@Position, 1 ) )
IF @Char BETWEEN ’A’ AND ’Z’
OR @Char BETWEEN ’0’ AND ’9’ BEGIN
SET @String = STUFF( @String,
@Position, 1, @Char )
SET @Position = 9999
END
END
END
RETURN( @String )
END
go
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接