473,396 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

INVALID LENGTH PARAMETER PASSED....

I have the follwoing stored procedure:

ALTER procedure [dbo].[up_GetExecutionContext](
@ExecutionGUID int = null
) as
begin
set nocount on

declare @s varchar(500)
declare @i int

set @s = ''
select @s = @s + EventType + ',' -- Dynamically build the list of
events
from(
select distinct top 100 percent [event] as EventType
from dbo.PackageStep
where (@ExecutionGUID is null or PackageStep.packagerunid =
@ExecutionGUID)
order by 1
) as x

set @i = len(@s)
select case @i
when 500 then left(@s, @i - 3) + '...' -- If string is too long then
terminate with '...'
else left(@s, @i - 1) -- else just remove the final comma
end as 'Context'

set nocount off
end --procedure
GO

When I run this and pass in a value of NULL, things work fine. When I
pass in an actual value (i.e. 15198), I get the following message:

Invalid length parameter passed to the SUBSTRING function.

There is no SUBSTRING being used anywhere in the query and the
datatypes look okay to me.

Any suggestions would be greatly appreciated.

Thanks!!

Jun 4 '07 #1
2 9148
On Jun 4, 12:43 pm, ansonee <anso...@yahoo.comwrote:
I have the follwoing stored procedure:

ALTER procedure [dbo].[up_GetExecutionContext](
@ExecutionGUID int = null
) as
begin
set nocount on

declare @s varchar(500)
declare @i int

set @s = ''
select @s = @s + EventType + ',' -- Dynamically build the list of
events
from(
select distinct top 100 percent [event] as EventType
from dbo.PackageStep
where (@ExecutionGUID is null or PackageStep.packagerunid =
@ExecutionGUID)
order by 1
) as x

set @i = len(@s)
select case @i
when 500 then left(@s, @i - 3) + '...' -- If string is too long then
terminate with '...'
else left(@s, @i - 1) -- else just remove the final comma
end as 'Context'

set nocount off
end --procedure
GO

When I run this and pass in a value of NULL, things work fine. When I
pass in an actual value (i.e. 15198), I get the following message:

Invalid length parameter passed to the SUBSTRING function.

There is no SUBSTRING being used anywhere in the query and the
datatypes look okay to me.

Any suggestions would be greatly appreciated.

Thanks!!
increase the value of @s from 500 to 5000 maybe and test it ?

Jun 4 '07 #2
ansonee (an*****@yahoo.com) writes:
set @s = ''
select @s = @s + EventType + ',' -- Dynamically build the list of
events
from(
select distinct top 100 percent [event] as EventType
from dbo.PackageStep
where (@ExecutionGUID is null or PackageStep.packagerunid =
@ExecutionGUID)
order by 1
) as x
I'm afraid that this relies on undefined behaviour. It may produce what
you want today. It might not tomorrow. If you are on SQL 2000, you
will need to run a cursor. On SQL 2005 there exists an option with
XML. See SQL Server MVP Antith Sen's article on
http://www.projectdmx.com/tsql/rowconcatenate.aspx for more information.
set @i = len(@s)
select case @i
when 500 then left(@s, @i - 3) + '...' -- If string is too
long then
terminate with '...'
else left(@s, @i - 1) -- else just remove the final comma
end as 'Context'

set nocount off
end --procedure
GO

When I run this and pass in a value of NULL, things work fine. When I
pass in an actual value (i.e. 15198), I get the following message:

Invalid length parameter passed to the SUBSTRING function.

There is no SUBSTRING being used anywhere in the query
No, but there is LEFT, which is just a shortcut for SUBSTRING.

More to the point, you have failed to handle the case that the query
does not find any events, and @i is the empty string.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jun 4 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it...
2
by: Rubycon | last post by:
Hi all, can anybody tell me what he invalid parameter is in this code. When I try to execute the mmioDescendParent I get a returncode 11, meaning that an invalid parameter has been passed. I...
2
by: Cole Shelton | last post by:
Hi all, I am trying to upload roughly 20-30k of binary data up to my webservice. At first, I just took my byte array and encoded it as a base64 string and passed it into my webservice. ...
9
by: Tom John | last post by:
Hi I am storing images in an access database, based on an MSDN article. The code i use to store is as follows: <code> 'Create the command object Dim command As New...
4
by: Trapulo | last post by:
I've a webservice with a string parameter. I call this webservice passing a string that is 1129 chars length. On the webservice, the received string is 1146 length (I tested sizes with...
0
by: jaffar | last post by:
Hi I am storing images in an access database, based on an MSDN article. The code i use to store is as follows: <code> 'Create the command object Dim command As New...
0
by: jaffar | last post by:
Hi I am storing images in an access database, based on an MSDN article. The code i use to store is as follows: <code> 'Create the command object Dim command As New...
9
by: AG | last post by:
I occassionally get the following exception from an ASP.NET 2.0 Web Application running on a shared web host. I have no way of knowing what the actual request page was as it never happens when I...
1
by: eBob.com | last post by:
I have some code which is trying to determine where text will wrap in a custom text box (which Inherits from Control). It determines the number of characters which will fit in the first line, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.