编写查询以按以下方式显示输出 [英] Write a query to display the output in the followin way
本文介绍了编写查询以按以下方式显示输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据是这样的.''.''111'',''bbb'',''333'',......''zzz''
如何以这种方式显示它..输出:-
111 bbb 333 ... .. ... zzz
解决方案
创建函数
创建 功能 dbo.testSplit( varchar (返回 @ temptable TABLE (项目 varchar ( 255 )) 为 开始 声明 @ idx int 声明 @ slice varchar ( 8000 ) 选择 @ idx = 1 如果 len( @ String )< 1 或 @ String 是 空 返回 同时 @idx!= 0 开始 set @ idx = charindex(' ,', @ String ) 如果 @idx!= 0 设置 @ slice = 左( @ String , @ idx - 1 ) 其他 设置 @ slice = @ String 如果(len( @ slice )> 0) 插入 插入 @ temptable (项目)值(转换( varchar ( 255 ), @ slice )) 设置 @ String = 右( @ String ,len( @ String )- @ idx ) 如果 len( @ String )= 0 休息 结束 返回 结束
然后这样称呼
select * from dbo.testSplit(''''''111'''',''''bbb'''',''''333'''''')
create a function
Create FUNCTION dbo.testSplit(@String varchar(8000)) returns @temptable TABLE (items varchar(255)) as begin declare @idx int declare @slice varchar(8000) select @idx = 1 if len(@String)<1 or @String is null return while @idx!= 0 begin set @idx = charindex(',',@String) if @idx!=0 set @slice = left(@String,@idx - 1) else set @slice = @String if(len(@slice)>0) insert into @temptable(Items) values(CONVERT(varchar(255), @slice)) set @String = right(@String,len(@String) - @idx) if len(@String) = 0 break end return end
and call it like that
select * from dbo.testSplit(''''''111'''',''''bbb'''',''''333'''''')
这篇关于编写查询以按以下方式显示输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文