如何得到以下的查询语句?

yeshucheng 2006-07-28 09:02:29
有一个这样的表如下:
id name object_name
19 kety org.per.ac.report.Report:45"
20 kety org.per.ac.report.Report:46"
21 kety org.per.ac.report.Report:47"

现在我想查出得到以下这样的效果:

id name object_name
19 kety 45
20 kety 46
21 kety 47
注:例如 org.per.ac.report.Report:45 冒号前面的是动态的,冒号后的数字长度也不定
...全文
534 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
yeshucheng 2006-07-30
  • 打赏
  • 举报
回复
我的问题解决了,这里特别感谢paoluo(一天到晚游泳的鱼)
真的很感谢你:)
pgsql是这样的:
subString(列名,position(':' in 列名),列名)就是这么简单:)
还要感谢大家的热心帮助
shareinfo 2006-07-28
  • 打赏
  • 举报
回复
还是一楼的写的比较简洁

==================================
= CSDN助手 全面支持CSDN论坛 =
= 监视、收藏、历史、签名走马灯 =
==================================
paoluo 2006-07-28
  • 打赏
  • 举报
回复
他加上了一個別名的。

不過現在大家寫的都是錯誤的,因為樓主不是MS SQL的數據庫。
昵称被占用了 2006-07-28
  • 打赏
  • 举报
回复
ALLEN625314() :

1楼写过了
九斤半 2006-07-28
  • 打赏
  • 举报
回复
▲ PK ★★★★ = ?
paoluo 2006-07-28
  • 打赏
  • 举报
回复
自大了點吧。
ALLEN625314 2006-07-28
  • 打赏
  • 举报
回复
以上偶滴答案才是正确的~一楼的很对,可是查询出来字段名字是“无列名”
me的才是正确的,嘎嘎
ALLEN625314 2006-07-28
  • 打赏
  • 举报
回复
select id,name,right(object_name,charindex(':',reverse(object_name))-1)'object_name' from tablename
yeshucheng 2006-07-28
  • 打赏
  • 举报
回复
stuff和charindex都不是内置的函数!
paoluo 2006-07-28
  • 打赏
  • 举报
回复
。。。開始怎麼不說。

你自己測試下這幾條語句吧,說不定有些可以用。
yeshucheng 2006-07-28
  • 打赏
  • 举报
回复
不知道大家熟悉postgresql吗?:)
确实不好意思,如果把这个查询的SQL改变成postgresql该怎么写呢
lxzm1001 2006-07-28
  • 打赏
  • 举报
回复
一下子这么多,楼主应该很高兴吧
昵称被占用了 2006-07-28
  • 打赏
  • 举报
回复
还是1、2楼的最好,不怕多个帽号
paoluo 2006-07-28
  • 打赏
  • 举报
回复
Create Table TEST
(id Int,
name Varchar(10),
[object_name] Varchar(50))
Insert TEST Select 19, 'kety', 'org.per.ac.report.Report:45"'
Union All Select 20, 'kety', 'org.per.ac.report.Report:46"'
Union All Select 21, 'kety', 'org.per.ac.report.Report:47"'
GO
Select
id,
Name,
Substring([object_name],CharIndex(':',[object_name])+1,CharIndex('"',[object_name])-CharIndex(':',[object_name])-1) As [object_name]
From TEST
Go
Drop Table TEST
GO
--Result
/*
id Name object_name
19 kety 45
20 kety 46
21 kety 47
*/
子陌红尘 2006-07-28
  • 打赏
  • 举报
回复
select id,name,stuff(object_name,1,charindex(':',object_name)+1,'') from tablename
paoluo 2006-07-28
  • 打赏
  • 举报
回复
Select
id,
Name,
Substring([object_name],CharIndex(':',[object_name])+1,CharIndex('"',[object_name])-CharIndex(':',[object_name])-1) As [object_name]
From TEST
fcuandy 2006-07-28
  • 打赏
  • 举报
回复
散分贴
lxzm1001 2006-07-28
  • 打赏
  • 举报
回复
select id,name,right(object_name,charindex(':',reverse(object_name))-1) as object_name from tablename
LouisXIV 2006-07-28
  • 打赏
  • 举报
回复
declare @test table
(
id int,
name varchar(4),
[object_name] varchar(40)
)
insert into @test
select 19, 'kety', 'org.per.ac.report.Report:45"' union all
select 19, 'kety', 'org.per.ac.report.Report:45678"' union all
select 19, 'kety', 'org.per.ac.repoerert.Report:352"'

select
id,
name,
reverse(substring(reverse([object_name]),2,charindex(':',reverse([object_name]))-2))
from @test


/*

id name
----------- ---- ----------------------------------------
19 kety 45
19 kety 45678
19 kety 352
*/
昵称被占用了 2006-07-28
  • 打赏
  • 举报
回复
保证只有一个帽号吗

select id,name,stuff(object_name,1,charindex(':',object_name),'') as object_name
from tablename

加载更多回复(3)

27,580

社区成员

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

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