传递给LEFT或SUBSTING函数的长度参数无效

时间:2018-02-24 02:48:17

标签: sql-server

Declare @FileNumber int

Set @FileNumber = cast (SubString(@fileName, CharIndex('Stats', @fileName) + 6, charindex('.',@fileName) - (CharIndex('Stats', @fileName) + 6)) as int)

我正在''传递@fileName并收到此错误。这是在SQL Server 2016中

1 个答案:

答案 0 :(得分:2)

因为......

select SubString('',  6 , - 6)

回归......

Msg 536, Level 16, State 1, Line 7
Invalid length parameter passed to the substring function.

https://docs.microsoft.com/en-us/sql/t-sql/functions/substring-transact-sql