求一條SQL查詢語句

wenjinhe 2006-04-21 02:45:57
我現在要求將一個字段下的數據用數字表示,示例如下:
SOR(字段)
2#3#6#
1#4#
3#5#6#
2#
5#7#
2#1#1#5#
......
要求查詢出來的數字是以#的個數為參照的(和#前面的數字無關)
SOR(字段)
3
2
3
1
2
4
......

請高手指點~~`
...全文
147 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xeqtr1982 2006-04-21
  • 打赏
  • 举报
回复
declare @t table(SOR varchar(20))
insert into @t select '2#3#6#'
union all select '1#4#'
union all select '3#5#6#'
union all select '2#'
union all select '5#7#'
union all select '2#1#1#5#'

select len(sor)-len(replace(sor,'#','')) as sor from @t
冷箫轻笛 2006-04-21
  • 打赏
  • 举报
回复

select (len(SOR) - len(replace(SOR,'#',''))) as SOR from table

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧