sqlserver为什么没有 substrb
答案:1 悬赏:80 手机版
解决时间 2021-01-03 19:42
- 提问者网友:雪舞兮
- 2021-01-03 14:48
sqlserver为什么没有 substrb
最佳答案
- 五星知识达人网友:西岸风
- 2021-01-22 06:14
没有你就自己写一个咯,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
createfunctiondbo.substrb(@demo nvarchar(100),@sub int,@len int)
returnsnvarchar(100)
as
begin
declare@datalen int,@cut nvarchar(100),@returnsnvarchar(100)
set@returns=''
set@cut=@demo
set@sub=@sub
while @sub>0
begin
--set @datalen=case when unicode(left(@cut,1)) between 97 and 122 then 1 when unicode(left(@cut,1)) between 65 and 90 then 1 else 2 end
set@datalen=casewhenunicode(left(@cut,1))<127 then1 else2 end
set@cut=right(@cut,len(@cut)-1)
set@sub=@sub-@datalen
end
while @len>0
begin
--set @datalen=case when unicode(left(@cut,1)) between 97 and 122 then 1 when unicode(left(@cut,1)) between 65 and 90 then 1 else 2 end
set@datalen=casewhenunicode(left(@cut,1))<127 then1 else2 end
set@len=@len-@datalen
if @len>=0
begin
set@returns=@returns+left(@cut,1)
set@cut=right(@cut,len(@cut)-1)
end
end
return(@returns)
end
go
declare@demo1 nvarchar(500),@demo2 nvarchar(500)
set@demo1=N'。,【】微软SqlServer数据库2014'
set@demo2=N'!@#$微软SqlServer数据库2014'
selectdbo.substrb(@demo1,0,6)
selectdbo.substrb(@demo2,0,6)
go
dropfunctiondbo.substrb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
createfunctiondbo.substrb(@demo nvarchar(100),@sub int,@len int)
returnsnvarchar(100)
as
begin
declare@datalen int,@cut nvarchar(100),@returnsnvarchar(100)
set@returns=''
set@cut=@demo
set@sub=@sub
while @sub>0
begin
--set @datalen=case when unicode(left(@cut,1)) between 97 and 122 then 1 when unicode(left(@cut,1)) between 65 and 90 then 1 else 2 end
set@datalen=casewhenunicode(left(@cut,1))<127 then1 else2 end
set@cut=right(@cut,len(@cut)-1)
set@sub=@sub-@datalen
end
while @len>0
begin
--set @datalen=case when unicode(left(@cut,1)) between 97 and 122 then 1 when unicode(left(@cut,1)) between 65 and 90 then 1 else 2 end
set@datalen=casewhenunicode(left(@cut,1))<127 then1 else2 end
set@len=@len-@datalen
if @len>=0
begin
set@returns=@returns+left(@cut,1)
set@cut=right(@cut,len(@cut)-1)
end
end
return(@returns)
end
go
declare@demo1 nvarchar(500),@demo2 nvarchar(500)
set@demo1=N'。,【】微软SqlServer数据库2014'
set@demo2=N'!@#$微软SqlServer数据库2014'
selectdbo.substrb(@demo1,0,6)
selectdbo.substrb(@demo2,0,6)
go
dropfunctiondbo.substrb
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯