troubleshooting Question

Invalid length parameter

Avatar of Mark Wilson
Mark Wilson asked on
Microsoft SQL Server 2008Microsoft SQL Server
2 Comments1 Solution77 ViewsLast Modified:
I have the following query I am using - it throws up the following error message

Invalid length parameter passed to the LEFT or SUBSTRING function.
The statement has been terminated.

Can anybody help?



;WITH [WL] AS (

SELECT        [L].[LookupId],
       [L].[LookupRuleSet],
       [L].[LookupVariety], 
       [L].[LookupType],
       [L].[LookupValue],
        REPLACE([L].[LookupString], '[' + [SV].[CA] + ']', '') [LookupString],
        [SV].[C] [CaseCategory]

FROM [Meta].[Lookup] [L]
LEFT OUTER JOIN (

       SELECT [CS].[LookupId],
              [CS].[CA],
              [SPLIT].[CS].value('.', 'INT') AS [C]

       FROM (

              SELECT [L].[LookupId],
                     LEFT(RIGHT([L].[LookupString], LEN([L].[LookupString]) - PATINDEX('%[[]%', [L].[LookupString])), PATINDEX('%]%', RIGHT([L].[LookupString], LEN([L].[LookupString]) - PATINDEX('%[[]%', [L].[LookupString]))) - 1) [CA],
                     CAST('<XL>' + REPLACE(LEFT(RIGHT([L].[LookupString], LEN([L].[LookupString]) - PATINDEX('%[[]%', [L].[LookupString])), PATINDEX('%]%', RIGHT([L].[LookupString], LEN([L].[LookupString]) - PATINDEX('%[[]%', [L].[LookupString]))) - 1), ',', '</XL><XL>') + '</XL>' AS XML) AS [C] 

              FROM [Meta].[Lookup]  [L]

       ) AS [CS] CROSS APPLY [C].nodes ('/XL') AS SPLIT([CS])

) AS [SV] ON [L].[LookupId] = [SV].[LookupId]

)



UPDATE  [Motor].Matter
SET     WorkSource = CASE WHEN [WL].[LookupValue] IS NULL THEN 'Others'
                          WHEN [Matter].[System] = 'IMELEgis' THEN 'IMe'
                          ELSE [WL].[LookupValue]
                     END
FROM    [Motor].[Matter] [Matter]
        LEFT OUTER JOIN [Motor].[Client] cl ON cl.ClaimID = Matter.ClaimID
        LEFT OUTER JOIN [WL] ON [Matter].[CaseType]
                                + COALESCE([Matter].[NUScheme], '') LIKE CASE
                                                              WHEN [WL].[LookupType] IN (
                                                              'Endswith',
                                                              'Wildcard' )
                                                              THEN '%'
                                                              ELSE ''
                                                              END
                                + REPLACE([WL].[LookupString], '||', '%')
                                + CASE WHEN [WL].[LookupType] IN (
                                            'Startswith', 'Wildcard' )
                                       THEN '%'
                                       ELSE ''
                                  END
                                AND [cl].[MotorCostLienCat2] = [WL].[CaseCategory]
                                AND [WL].[LookupRuleSet] = 'Motor'
                                AND [WL].[LookupVariety] = 'Worksource'

Open in new window

ASKER CERTIFIED SOLUTION
Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 2 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 2 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004