June 16, 2016 at 12:26 pm
Msg 537, Level 16, State 3, Line 16
Invalid length parameter passed to the LEFT or SUBSTRING function.
We have a proc which inserts data into a table, selects from a view.
This procedure fails with the above error ... can anyone please help ... I see no traces of any functions in the code...its plain simple query with insert into table, select * from view.
June 16, 2016 at 12:37 pm
What is the structure of the view?
That may be where the issue is coming from.
It's probably doing something like this:
DECLARE @s-2 varchar(100) = '12345'
SELECT LEFT(@s, CHARINDEX('x', @s-2) - 1)
In this example, the code is looking for the first occurrence of 'X' in a string. If it's found, it returns everything to the left of that.
If it's not found, it returns the error.
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
June 16, 2016 at 12:51 pm
On the table where it inserts the data.
We had issues with that table and had to import data from last good backup. After that we have this proc failing with that error.
Before that table import, there were no issues with the code...
June 16, 2016 at 2:19 pm
The data is bad.
There are probably records with an empty string. Without knowing what the code is trying to do, that is a guess.
Can you post the code from the view?
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
June 16, 2016 at 8:39 pm
You say that the procedure fails, but which part? Is it the insert or the query that fails?
Can you post the code?
June 17, 2016 at 2:39 am
Is there a trigger on the table? Or any other constraint or computed column that might be causing this?
Thomas Rushton
blog: https://thelonedba.wordpress.com
June 17, 2016 at 7:07 am
I think we're going to need the table definition and procedure code to be able to offer any advice. Generic recommendations and questions are just that - generic, and have a low chance of helping you find the problem.
June 17, 2016 at 7:16 am
All - thanks for your assistance- The issue was with bad data.
June 17, 2016 at 7:21 am
krishna85 (6/17/2016)
All - thanks for your assistance- The issue was with bad data.
Glad you got it figured out.
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply