当前位置:网站首页>Sqlserver gets the data of numbers, Chinese and characters in the string
Sqlserver gets the data of numbers, Chinese and characters in the string
2022-06-30 21:21:00 【※※ Bingxin ※※】
-- Get English character data
Create function [dbo].[Fun_GetChar]
(
@No varchar(100)
)
RETURNS varchar(100)
AS
BEGIN
WHILE PATINDEX('%[^A-Za-z]%',@No)>0
BEGIN
SET @No=STUFF(@No,PATINDEX('%[^A-Za-z]%',@No),1,'')
END
RETURN CONVERT(varchar(100),@No)
END--select dbo.F_GetChar('2.5mg')-- Call function =mg
-- Get numeric data
Create FUNCTION [dbo].[Fun_GetNum]
( @Str NVARCHAR(MAX) )
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @Start INT;
DECLARE @End INT;
DECLARE @Part NVARCHAR(MAX)
SET @Start = PATINDEX('%[.,0-9]%', @Str);
SET @End = PATINDEX('%[.,0-9]%',SUBSTRING(@Str, @Start+1,LEN(@Str) - @Start));
SET @Part = SUBSTRING(@Str,@Start,1)
WHILE @End >0
BEGIN
SET @Start = @[email protected]
SET @Part = @Part+SUBSTRING(@Str,@Start,1)
SET @End = PATINDEX('%[0-9]%',SUBSTRING(@Str, @Start+1,LEN(@Str) - @Start));
END
RETURN @Part;
END;--seleect dbo.[Fun_GetNumPart]('2.5mg')-- Call function =2.5
-- Get Chinese data
create function [dbo].[Fun_getCN]
(@str varchar(4000))
returns varchar(4000)
as
begin
declare @word nchar(1),@CN varchar(4000)
set @CN=''
while len(@str)>0
begin
set @word=left(@str,1)
if unicode(@word) between 19968 and 40869
set @[email protected][email protected]
set @str=right(@str,len(@str)-1)
end
return @CN
end
GO --select dbo.[Fun_getCN('2.5mg, mg ')-- Call function = mg
边栏推荐
猜你喜欢

How to move forward when facing confusion in scientific research? How to give full play to women's advantages in scientific research?

asp.net core JWT传递

go搭建服务器基础

MySQL introduction, detailed installation steps and usage | dark horse programmer

3Ds Max 精模obj模型导入ArcGIS Pro (二)要点补充

《ClickHouse原理解析与应用实践》读书笔记(3)

文本识别-SVTR论文解读

时空数据挖掘:综述

毕业五年,想当初若没有入行测试,我是否还会如这般焦虑

【无标题】
随机推荐
Auto-created primary key used when not defining a primary key
升级kube出现unknown flag: --network-plugin
jenkins下载插件下载不了,解决办法
[untitled]
遇到“word在试图打开文件时遇到错误”怎么办?
凤凰架构——架构师的视角
Go build server Foundation
测试媒资缓存问题
文本识别-SVTR论文解读
To the Sultanate of Anderson
一文读懂什么是MySQL索引下推(ICP)
Coefficient of variation method matlab code [easy to understand]
How to run jenkins build, in multiple servers with ssh-key
. NETCORE redis geo type
ArcGIS construction and release of simple road network data service and rest call test
文本生成模型退化怎麼辦?SimCTG 告訴你答案
MySQL batch update
CA I ah, several times Oh, ah, a sentence IU home Oh
Double solid histogram / double y-axis
19.04 distributor