To find out the data that caused the sql queries stopped


I have a queries that run perfectly and this query run to extract millions of reports, today query stopped with ssms returned me an error below, how do I find out the query stopped at which data ?

Msg 537, Level 16, State 3, Line 1
Invalid length parameter passed to the LEFT or SUBSTRING function.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HuaMin ChenProblem resolverCommented:
Check whatever Left or Substring part in the query. there should be invalid parameter passed to that. For instance, there is only 3 characters on the left, but you pass 4 or more.
motioneyeAuthor Commented:
here is the query syntax that caused the query stopped

select  [Based]=ltrim(rtrim(replace(  
      substring( rtrim(left([Category], charindex('UnixPath:',[Category],0)-1))  
                          ,charindex('Based:',rtrim(left([Category], charindex('UnixPath:',[Category],0)-1)),1)  
                          ,'Based: ','')))  
,[UnixPath]=  replace(ltrim(rtrim(right([Category], len([Category])-charindex('UnixPath:',[Category],0)+1))),'UnixPath: ','')
FROM TableBasedA  
anyone could explain what the query actually does here ?
My guess is that there are records where [Category] does not have the string 'UnixPath' in it, so SUBSTRING is choking on a zero value. Try running this to find out if that's a common occurrence:
SELECT * FROM TableBasedA WHERE CHARINDEX('UnixPath:', [Category]) = 0;

Open in new window

The short explanation is that this code is splitting the [Category] field into two new fields, [Based] and [UnixPath].

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
motioneye, do you still need help with this question?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.