如何在sybase中获取该列位于其他查询中的查询中的部分列值? [英] How to get part of the column value in sybase where this column situated in a query which is inside other query?

查看:54
本文介绍了如何在sybase中获取该列位于其他查询中的查询中的部分列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在名为 Conses 的表中有一个名为 Cons 的列作为 Order::Resource(PPP32#BB300320LQ00J#AAAR05504)我有第二张桌子,它取决于第一张桌子.我想从秒表中获取所有数据,我按如下方式手动完成,结果正常

I have a column named Cons in a table named Conses as Order::Resource(PPP32#BB300320LQ00J#AAAR05504) I have second table which depends on first table. i wants to get all data from the seconds table and i did it manually as below and result is ok

select * from so_db..item   where  id =('PPP32' )
                            and    sub_id =('BB300320LQ00J')
                            and    tem_id =('AAAR05504');

但我想用另一个查询替换括号内,该查询必须获取上述列的一部分,如下所示:

but i want to replace inside the parentheses with an other query which must get one part of the column mentioned above as follow:

id = '#' 字符之前的列的第一部分

id = first part of column before '#' character

sun_id = '#' 字符之间的列中间部分

sun_id = middle part of column between '#' character

tem_id = 列的最后一部分

tem_id = last part of column

select * from so_db..item   where  id =( select Cons from er_db..Conses where UsedBy_ = 'mmmf8c713f490f8133c00e16ffdea136add')
                            and    sub_id =(select Cons from er_db..Conses where UsedBy_ = 'mmmf8c713f490f8133c00e16ffdea136add')
                            and    tem_id =(select Cons from er_db..Conses where UsedBy_ = 'mmmf8c713f490f8133c00e16ffdea136add');

有人知道怎么做吗?

推荐答案

你只需要进行字符串操作.

You simply have to do string manipulation.

使用 子字符串charindexchar_length, right 功能 :)

Use substring, charindex, char_length, right and left functions :)

declare @string varchar(50)
select @string = 'Order::Resource(PPP32#BB300320LQ00J#AAAR05504)'
declare @start int, @end int, @secondstring varchar(100)

select @start = charindex('#',@string)
select @secondstring = substring(@string, @start+1, len(@string))

select @end = charindex('#',@secondstring)

select substring(@string,charindex('(', @string)+1, @start-1-charindex('(', @string)),
       substring(@string,@start+1,@end-1), 
       substring(@string, @start+@end+1, len(@string)-(@start+@end+1))

这篇关于如何在sybase中获取该列位于其他查询中的查询中的部分列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆