问题描述
我有以下记录的表评论
原因
1148339 - GI NAGALOURGO
2108345 - VE DIWALOURGO
从上表我想要的输出如下
原因ID名称
1148339 - GI NAGALOURGO 1148339 GI NAGALOURGO
2108345 - VE DIWALOURGO 2108345 VE DIWALOURGO
对于我写的查询如下
选择原因,左(原因,CHARINDEX(' - ',原因)-1),
STUFF(原因,1,CHARINDEX(' - ',原因),'')
来自评论
当我运行上述查询时显示错误如下
传递给LEFT或SUBSTRING函数的长度参数无效。
如何解决以上错误。我上面的查询中有什么错误。
我尝试过:
I have table comments with records as follows
Reason
1148339 - GI NAGALOURGO
2108345 - VE DIWALOURGO
From the above table i want output as follows
Reason ID Name
1148339 - GI NAGALOURGO 1148339 GI NAGALOURGO
2108345 - VE DIWALOURGO 2108345 VE DIWALOURGO
for that i written query as follows
select Reason, Left(Reason, CHARINDEX('-', Reason)-1) ,
STUFF( Reason, 1, CHARINDEX('-', Reason), '')
from comments
when i run the above query shows error as follows
Invalid length parameter passed to the LEFT or SUBSTRING function.
how to solve the above error. what is the mistake in my above query.
What I have tried:
I have table comments with records as follows
Reason
1148339 - GI NAGALOURGO
2108345 - VE DIWALOURGO
From the above table i want output as follows
Reason ID Name
1148339 - GI NAGALOURGO 1148339 GI NAGALOURGO
2108345 - VE DIWALOURGO 2108345 VE DIWALOURGO
for that i written query as follows
select Reason, Left(Reason, CHARINDEX('-', Reason)-1) ,
STUFF( Reason, 1, CHARINDEX('-', Reason), '')
from comments
when i run the above query shows error as follows
Invalid length parameter passed to the LEFT or SUBSTRING function.
how to solve the above error. what is the mistake in my above query.
推荐答案
这篇关于我试过它在SQL服务器中显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!