作者:爱他让我心痛_830 | 来源:互联网 | 2023-05-19 04:52
I have this kind of strings in a table:
表中有这样的字符串:
- AM-65-800
- - 65 - 800
- AM-75/86-650
- am - 75/86 - 650吗
- D-27-600
- d - 27 - 600
What I'm trying to do is to get only the middle part, for example:
我想做的是只得到中间的部分,例如:
Basically the substring after and before the '-' Char
基本上,在“-”字符前后的子字符串
I tried this (from an example in here):
我试过(从这里的一个例子):
SELECT SUBSTRING(Product.Name, LEN(LEFT(Product.[Name], CHARINDEX ('-', Product.[Name]))) + 1, LEN(Product.[Name]) - LEN(LEFT(Product.[Name], CHARINDEX ('-', Product.[Name]))) - LEN(RIGHT(Product.[Name], LEN(Producto.[Name]) - CHARINDEX ('-', Product.[Name]))) - 1)
FROM Product
But it gives me this error:
但它给了我一个错误:
[42000] [Microsoft][SQL Server Native Client 10.0][SQL Server]Invalid length parameter passed to the LEFT or SUBSTRING function. (537)
Being honest, I don't know how to solve the error because I don't understand the solution from the example. what can I do?
老实说,我不知道如何解决这个错误,因为我不理解这个例子的解决方案。我能做什么?
Thanks.
谢谢。
3 个解决方案