Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312

    Unanswered: SQL Server equivalent to InStr

    Being new to SQL Server and in a crunch for time, can someone help me with the SQL Server equivalent of the InStr function. I am trying to find where the '-' is in a string and get the first n characters.

    Example Order Numbers:

    1000015-01
    100001-1
    100002-02


    I need the characters before the -.

    Thanks in advance for your help.

  2. #2
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    I believe PATINDEX is what I need, but now if the - is not in the Order number (sometimes it is not) then I am not getting the results I want. I would normally use IIF in Access to determine whether or not to use LEFT with the results from PATINDEX or not.

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    You can use CASE in TSQL where you would normally use IIF in access.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    That's what I needed! Thanks.

Posting Permissions

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