Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2009
    Posts
    14

    Unanswered: issue while using substring, charindex together

    charindex('.',mycolumnName) returns proper value
    charindex('.',mycolumnName)-1 also returns proper value

    but when i used to use the below query,

    select substring(mycolumnName,1,(charindex('.',mycolumnNa me)-1)) from myTablename

    am getting [Error Code: 536, SQL State: S1000] Invalid length parameter with value of -1 passed to the substring function

    How to resolve this in Sybase ASE ?
    Vikram RM

  2. #2
    Join Date
    Mar 2009
    Location
    Sydney, Australia
    Posts
    258
    That's a simple programming error. Let's say charindex('.',mycolumnName)-1 produces x where there is a '.' in the column; it will produce -1 where there is none. You want the substring to extract a string starting at 1 [correct ?] for the length of x [correct ?]. That works nicely when you have a '.' somewhere in the data. What happens when you have none ?

    Select mycolumnName where charindex('.',mycolumnName) = 0
    Regards
    Derek Asirvadem (Formerly DerekA)
    Information Architect / Senior Sybase DBA
    Copyright 2009 Software Gems Pty Ltd

    I answer questions from the Original Poster only. If you have a genuine question, as the moderators have requested, start a new thread.

    http://www.softwaregems.com.au

Posting Permissions

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