关于sql截取字符串问题 索引号:3|成本会计|索引号:37|对外经济管理概论|现在我想将 数字3 和37截取出来怎么做?谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 --如:Select Left('3212|成本会计|',Charindex('|','3212|成本会计|')-1) select substring(索引号,1,charindex('|',索引号)) Declare @S Nvarchar(200)Select @S = N'索引号:3|成本会计|'--Select @S = N'索引号:37|对外经济管理概论|'Select Rtrim(Substring(@S, CharIndex(':', @S) + 1, CharIndex('|', @S) - CharIndex(':', @S) - 1))--Result3 declare @str varchar(50)set @str = '37|对外经济管理概论|'print substring(@str,patindex('%[1-9]%',@str),len(@str)-patindex('%[1-9]%',reverse(@str))+1) 查詢Select Rtrim(Substring(ColName, CharIndex(':', ColName) + 1, CharIndex('|', ColName) - CharIndex(':', ColName) - 1)) As ColName From TableName select left(col,charindex(col1,'|')-1) from table --如果“索引号”是字段名的話Declare @S Nvarchar(200)Select @S = N'3|成本会计|'--Select @S = N'37|对外经济管理概论|'Select Rtrim(Substring(@S, 1, CharIndex('|', @S) - 1))--Result/*3*/--查詢Select Rtrim(Substring(索引号, 1, CharIndex('|', 索引号) - 1)) From TableName xierimin(xierimin(承接网站建设业务)) ( ) 信誉:100 Blog 2007-03-05 17:37:55 得分: 0 索引号:3|成本会计|索引号:37|对外经济管理概论|是两条完整的字符串,不是'3212|成本会计|' -------那我開始寫的就是對的。Declare @S Nvarchar(200)Select @S = N'索引号:3|成本会计|'--Select @S = N'索引号:37|对外经济管理概论|'Select Rtrim(Substring(@S, CharIndex(':', @S) + 1, CharIndex('|', @S) - CharIndex(':', @S) - 1))--Result/*3*/--查詢Select Rtrim(Substring(ColName, CharIndex(':', ColName) + 1, CharIndex('|', ColName) - CharIndex(':', ColName) - 1)) As ColName From TableName declare @str varchar(50)set @str = '37|对外经济管理概论|'print substring(@str,patindex('%[1-9]%',@str),len(@str)-patindex('%[1-9]%',reverse(@str))+1)--不管数字在哪里都一样提取出来 牛人请进 关于内联视图 日期转换问题 谁能帮我解答一下下面的题目 菜鸟提问时间~~~ 怎么登录上这个SQL2005 哪位大哥帮我写一个存储过程呀:( 怎么样能让这个过程最快啊 (在线等待,急急急)写数据入数据库问题 MFC+SQL2008 表连接问题 字符串有数字排序 求一序号问题,急!!!
Select Left('3212|成本会计|',Charindex('|','3212|成本会计|')-1)
Select @S = N'索引号:3|成本会计|'
--Select @S = N'索引号:37|对外经济管理概论|'
Select Rtrim(Substring(@S, CharIndex(':', @S) + 1, CharIndex('|', @S) - CharIndex(':', @S) - 1))
--Result
3
set @str = '37|对外经济管理概论|'
print substring(@str,patindex('%[1-9]%',@str),len(@str)-patindex('%[1-9]%',reverse(@str))+1)
Rtrim(Substring(ColName, CharIndex(':', ColName) + 1, CharIndex('|', ColName) - CharIndex(':', ColName) - 1)) As ColName
From TableName
Select @S = N'3|成本会计|'
--Select @S = N'37|对外经济管理概论|'
Select Rtrim(Substring(@S, 1, CharIndex('|', @S) - 1))
--Result
/*
3
*/--查詢
Select Rtrim(Substring(索引号, 1, CharIndex('|', 索引号) - 1)) From TableName
索引号:3|成本会计|
索引号:37|对外经济管理概论|
是两条完整的字符串,不是'3212|成本会计|'
-------那我開始寫的就是對的。
Declare @S Nvarchar(200)
Select @S = N'索引号:3|成本会计|'
--Select @S = N'索引号:37|对外经济管理概论|'
Select Rtrim(Substring(@S, CharIndex(':', @S) + 1, CharIndex('|', @S) - CharIndex(':', @S) - 1))
--Result
/*
3
*/--查詢Select
Rtrim(Substring(ColName, CharIndex(':', ColName) + 1, CharIndex('|', ColName) - CharIndex(':', ColName) - 1)) As ColName
From TableName
set @str = '37|对外经济管理概论|'
print substring(@str,patindex('%[1-9]%',@str),len(@str)-patindex('%[1-9]%',reverse(@str))+1)--不管数字在哪里都一样提取出来