Cutting a Column Apart

  • Hi All,

     

    I have this figured out in Crystal but can't seem to get it to work in SQL.  I have a column where I want to grab everything but the first 19 characters.  In Crystal I am using this command:

    TrimRight({Incident_Details.Description}[20 to 35])

    But I cannot find a similar command in SQL, I was thinking of a left and/or right but that wont work because the characters at the end of the field could be 6, 8, or more characters. 

    Anyone???

    Thanks!

    Tim

  • How about

    substring(Incident_Details.Description, 20, len(Incident_Details.Description) -19)

    That should work, but beware of columns with length < 20

     

    Stephen

  • Stephen's right...you could use a case statement to avoid the < 20 pitfall:

    CASE WHEN len(Incident_Details.Description) < 20 then '' ELSE

    substring(Incident_Details.Description, 20, len(Incident_Details.Description) -19) END AS DESCRIPTION

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Infact RIGHT function should also work

    SELECT

    CASE WHEN LEN(Incident_Details.Description) > 19 THEN RIGHT(Incident_Details.Description,LEN(Incident_Details.Description)-19) ELSE '' END AS Description

    FROM

    Incident_Details

    Prasad Bhogadi
    www.inforaise.com

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply