高手帮我看看 为什么会报这个错误

jaydom 2010-06-01 03:49:19

create table ta ( num varchar(10) )
insert into ta
select 1 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 10 union all
select 110 union all
select 101

create table tb (编号 varchar(10),公交路线 varchar(100))
insert into tb
select '10001', '1,101' union all
select '10002', '10,110'


;with t
as
(
select a.编号, cast(SUBSTRING(a.公交路线,number,CHARINDEX(',',a.公交路线+',',number)-b.number) as varchar(100)) col
from tb a join master..spt_values b on b.type='p' and CHARINDEX(',',','+a.公交路线,number)=number
)
select *
from tb join t on t.编号=tb.编号
where t.col='10'

消息 537,级别 16,状态 2,第 1 行
传递给 LEFT 或 SUBSTRING 函数的长度参数无效。

...全文
119 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jaydom 2010-06-01
  • 打赏
  • 举报
回复
谢谢各位sf ,问题解决了 结贴
--小F-- 2010-06-01
  • 打赏
  • 举报
回复
传递给 LEFT 或 SUBSTRING 函数的长度参数无效 检查下SUBSTRING函数中的长度是不是数值
无心雨云 2010-06-01
  • 打赏
  • 举报
回复
没注意,连的是系统表
无心雨云 2010-06-01
  • 打赏
  • 举报
回复
number is null
未处理吧
永生天地 2010-06-01
  • 打赏
  • 举报
回复
;with t
as
(
select a.编号, cast(SUBSTRING(a.公交路线,number,CHARINDEX(',',a.公交路线+',',number)-b.number) as varchar(100)) col
from tb a join master..spt_values b on b.type='p' and CHARINDEX(',',','+a.公交路线,number)=number and b.number between 1 and len(a.公交路线)
)
select *
from tb join t on t.编号=tb.编号
where t.col='10'
无心雨云 2010-06-01
  • 打赏
  • 举报
回复
没看到有[number]这个字段啊
jaydom 2010-06-01
  • 打赏
  • 举报
回复
顶一下 怎么没人来啊

22,302

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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