RICHEER COCA 2022-02-13 20:19 采纳率: 93.9%
浏览 24
已结题

除了用 STRING_SPLIT重新排序 现在学习下面的函数,但是老数据没有更新,但不知道错误出现在哪里?特此提问请教

除了用 STRING_SPLIT重新排序 现在学习下面的函数,但是老数据没有更新,但不知道错误出现在哪里?特此提问请教
/***
-- 建函数    需要对应 数据库
create function fn_newnotext
(@notext nvarchar(29)) returns nvarchar(40)
as
begin
 declare @n nvarchar(29)
 declare @t table(x nvarchar(10))
  
 insert into @t(x)
  select substring(a.s,b.number,charindex(' ',a.s+' ',b.number)-b.number)
  from (select @notext 's') a
  inner join master.dbo.spt_values b 
  on b.[type]='P' and b.number between 1 and len(a.s) and substring(' '+a.s,b.number,1)=' '
  order by substring(a.s,b.number,charindex(' ',a.s+' ',b.number)-b.number)
  
 select @n=isnull(@n+' ','')+x
  from @t
 
 return @n
end
***/

----->更新前的老数据报表 每一行的数字不是从小到大的顺序

DROP TABLE IF EXISTS  #test --  select * from #test
 
create table #test([MID] [int] IDENTITY(1,1) NOT NULL primary key,notext varchar(30)) 
insert into #test 
 select '30 51 54 09 16 77 67 59 13 43'
union all  select '54 09 16 77 67 59 13 43 15 44'
union all  select '16 77 67 59 13 43 15 44 63 52'
union all  select '67 59 13 43 15 44 63 52 48 27'
union all  select '13 43 15 44 63 52 48 27 11 03'
union all  select '15 44 63 52 48 27 11 03 60 23'
union all  select '63 52 48 27 11 03 60 23 12 75'

-- 更新

update [#test] set notext=dbo.fn_newnotext(notext)
 
-- 更新后数据 每行数字从小到大的顺序
select * from #test
order by MID

--想要的结果如下(上面的脚本执行后数据并没有改变)
---------------------------------------------
NoText
09 13 16 30 43 51 54 59 67 77
09 13 15 16 43 44 54 59 67 77
13 15 16 43 44 52 59 63 67 77
13 15 27 43 44 48 52 59 63 67
03 11 13 15 27 43 44 48 52 63
03 11 15 23 27 44 48 52 60 63
03 11 12 23 27 48 52 60 63 75
  • 写回答

2条回答 默认 最新

  • DarkAthena ORACLE应用及数据库设计方案咨询师 2022-02-14 01:14
    关注

    先不急着更新,尝试先select这个函数,传入某一条记录的字符串,看看查出来是什么东西

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 2月22日
  • 已采纳回答 2月14日
  • 修改了问题 2月13日
  • 创建了问题 2月13日

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c