Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2004
    Posts
    93

    Unanswered: invalied length parameter passed the substring function

    Does anyone know what the above error message means?
    Cheers
    Etravels

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    What length did you pass to substring?

  3. #3
    Join Date
    Feb 2004
    Posts
    93

    ?

    What do you mean, what length...
    Cheers
    Etravels

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    From the SQL Server Books Online (a.k.a. BOL):

    SUBSTRING
    Returns part of a character, binary, text, or image expression. For more information about the valid Microsoft® SQL Server™ data types that can be used with this function, see Data Types.

    Syntax
    SUBSTRING ( expression , start , length )

    Arguments
    .....

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Code:
    DECLARE @x int, @y int, @z varchar(8000)
    
    -- This works
    SELECT @x = 47, @y = 22, @z = 'Even if God Almighty, points his finger at us, It just Doesnt matter'
    SELECT SUBSTRING(@z,@x,@y)
    
    -- This works in SQL Server...DB2's head would explode though since it's out of range
    SELECT @x = 47, @y = 8000
    SELECT SUBSTRING(@z,@x,@y)
    
    -- Same as the above...really doesn't make a whole lot of sense though
    SELECT @x = 47, @y = 0
    SELECT SUBSTRING(@z,@x,@y)
    
    -- So the Only thing that doesn't work is a negative...but the way sql works...probably could have allowed it
    -- Would have been neat to go to the left in the string for negative nymbers
    SELECT @x = 47, @y = -1
    SELECT SUBSTRING(@z,@x,@y)
    EDIT: Oh, most likely you have code that's deriving the length..post the code and we can figure it out...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •