【转载】MSSQL汉字首字母查询处理自定义函数
2021/10/25 2:09:32
本文主要是介绍【转载】MSSQL汉字首字母查询处理自定义函数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
-- 汉字首字母查询处理用户定义函数 CREATE FUNCTION f_GetPY(@str nvarchar(4000)) RETURNS nvarchar(4000) AS BEGIN DECLARE @py TABLE( ch char(1), hz1 nchar(1) COLLATE Chinese_PRC_CS_AS_KS_WS, hz2 nchar(1) COLLATE Chinese_PRC_CS_AS_KS_WS) INSERT @py SELECT 'A',N'吖',N'鏊' UNION ALL SELECT 'B',N'八',N'簿' UNION ALL SELECT 'C',N'嚓',N'错' UNION ALL SELECT 'D',N'哒',N'跺' UNION ALL SELECT 'E',N'屙',N'贰' UNION ALL SELECT 'F',N'发',N'馥' UNION ALL SELECT 'G',N'旮',N'过' UNION ALL SELECT 'H',N'铪',N'蠖' UNION ALL SELECT 'J',N'丌',N'竣' UNION ALL SELECT 'K',N'咔',N'廓' UNION ALL SELECT 'L',N'垃',N'雒' UNION ALL SELECT 'M',N'妈',N'穆' UNION ALL SELECT 'N',N'拿',N'糯' UNION ALL SELECT 'O',N'噢',N'沤' UNION ALL SELECT 'P',N'趴',N'曝' UNION ALL SELECT 'Q',N'七',N'群' UNION ALL SELECT 'R',N'蚺',N'箬' UNION ALL SELECT 'S',N'仨',N'锁' UNION ALL SELECT 'T',N'他',N'箨' UNION ALL SELECT 'W',N'哇',N'鋈' UNION ALL SELECT 'X',N'夕',N'蕈' UNION ALL SELECT 'Y',N'丫',N'蕴' UNION ALL SELECT 'Z',N'匝',N'做' DECLARE @i int SET @i=PATINDEX('%[吖-做]%' COLLATE Chinese_PRC_CS_AS_KS_WS,@str) WHILE @i>0 SELECT @str=REPLACE(@str,SUBSTRING(@str,@i,1),ch) ,@i=PATINDEX('%[吖-做]%' COLLATE Chinese_PRC_CS_AS_KS_WS,@str) FROM @py WHERE SUBSTRING(@str,@i,1) BETWEEN hz1 AND hz2 RETURN(@str) END
这篇关于【转载】MSSQL汉字首字母查询处理自定义函数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-01-08Docker下的SqlServer发布订阅启用
- 2023-06-05Docker安装MS SQL Server并使用Navicat远程连接
- 2023-05-25深入浅出 SQL Server CDC 数据同步
- 2023-05-12通过空间占用和执行计划了解SQL Server的行存储索引
- 2023-04-24以SQLserver为例的Dapper详细讲解
- 2022-11-30SQL server高级函数查询
- 2022-11-26SQL SERVER数据库服务器CPU不能全部利用原因分析
- 2022-11-21SQL Server 时间算差值/常用函数
- 2022-11-20调试Archery连接SQL Server提示驱动错误
- 2022-10-22SQL Server 完整、差异备份+完整、差异还原(详细讲解,规避错误)