SQL取字符求助

No45376 2008-09-16 11:23:02
列名为 I
这是列的内容:A=6574,B=123,V1.67,IP=59.174.85.146

想得到A+B的和,菜鸟望大虾指点下
...全文
299 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
hyqwan11112 2008-09-16
  • 打赏
  • 举报
回复

--做出来是没问题,但觉得在前台做要好得多
--我这写了一个,看长度都有点恐怖,不过可以达到你想要的效果,呵呵
declare @tt nvarchar(200)
set @tt = 'A=6574,B=123,V1.67,IP=59.174.85.146'
select cast(substring(@tt,charindex('=',@tt)+1,charindex(',',@tt)-charindex('=',@tt)-1) as int)
+substring(stuff(@tt,1,charindex(',',@tt),''),charindex('=',stuff(@tt,1,charindex(',',@tt),''))+1,charindex(',',stuff(@tt,1,charindex(',',@tt),''))-charindex('=',stuff(@tt,1,charindex(',',@tt),''))-1)
wzy_love_sly 2008-09-16
  • 打赏
  • 举报
回复
declare @s varchar(100)
set @s='A=6574,B=123,V1.67,IP=59.174.85.146'
select cast(replace(parsename(replace(replace(@s,'.',''),',','.'),4),'a=','') as int)*replace(parsename(replace(replace(@s,'.',''),',','.'),3),'b=','')


808602
中国风 2008-09-16
  • 打赏
  • 举报
回复

declare @s nvarchar(1000)
set @s='A=6574,B=123,V1.67,IP=59.174.85.146'

select
cast(substring(@s,charindex('A=',@s)+2,charindex(',B',@s)-3) as int)+substring(@s,charindex('B=',@s)+2,charindex(',V',@s)-charindex('B=',@s)-2)


-----------
6697

(1 個資料列受到影響)

zheninchangjiang 2008-09-16
  • 打赏
  • 举报
回复
用数据库存储还行,居然还要用TSQL来求解,不是一般的强,建议用C#去做吧.
昵称被占用了 2008-09-16
  • 打赏
  • 举报
回复
晕哦
这是数据库吗?
No45376 2008-09-16
  • 打赏
  • 举报
回复
呵呵,这是别人出的题目,做的练手的,谢谢啦

27,579

社区成员

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

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