w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Invalid length parameter passed to the LEFT or SUBSTRING function in row concatenation

The error is coming from your ORDER BY clause. You do not have it wrapped in a condition (CASE or IIF) like you have in the SELECT. Change your ORDER BY to be the following:

 ORDER BY CASE WHEN CHARINDEX('{', wp.[description]) > 0 THEN

 CONVERT(INT, 
    SUBSTRING(wp.[description],
              CHARINDEX('{', wp.[description]) + 1,
              CHARINDEX('}', wp.[description]) - CHARINDEX('{',
wp.[description]) - 1)
     )
     ELSE 0 
    END;

Also, it is not a good idea to specify the return type as simply VARCHAR without a length. The default width of a VARCHAR / NVARCHAR is either 1 or 30, depending on the context in which it is being stated. Since your local variable is declared as VARCHAR(1000), you should use the same 1000 for the declaration of the output type.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.