SQL 获取字符串中大写字母或小写字母

时间:2022-05-24 09:25:12
【文件属性】:

文件名称:SQL 获取字符串中大写字母或小写字母

文件大小:1KB

文件格式:SQL

更新时间:2022-05-24 09:25:12

SQL

if exists(select * from sys.objects where name='GetUpper') drop function dbo.GetUpper go CREATE function GetUpper(@words varchar(16)) returns varchar(8000) as begin DECLARE @s VARCHAR(MAX)= @words --待截取字符串 DECLARE @temp VARCHAR(MAX)='' --临时变量 SELECT @temp=@temp+SUBSTRING(ch, sv.number, 1) FROM (SELECT @s AS ch) t CROSS APPLY [master].dbo.spt_values AS sv WHERE sv.type = 'P' AND sv.number BETWEEN 1 AND LEN(ch) AND ASCII(SUBSTRING(ch, sv.number, 1)) BETWEEN ASCII('A') AND ASCII('Z') return @temp end go


网友评论