locked
Trim the left string. RRS feed

  • Question

  • I want to trim from the field 'Group Criteria' which has couple of values as below. Trim from 'Participant has a diagnosis of one of the following based on study definitions; -' and keep the rest. What is the command to do it.

    1.Participant has a diagnosis of one of the following based on study definitions; -   New Onset Diabetes

    2. Participant has a diagnosis of one of the following based on study definitions; -  Long standing Diabetes 

    Thursday, October 18, 2018 8:13 PM

Answers

  • Hi Ri1_2,

    According to your description, my understanding is that you want to SELECT part of the value in the column 'Group Criteria' like the following text. If anything is misunderstood, please tell me.

    *-------former----------- 
    Group Criteria
    --------------------------------
    Participant has a diagnosis of one of the following based on study definitions; -  New Onset Diabetes
    Participant has a diagnosis of one of the following based on study definitions; -  Long standing Diabetes                  
    */
    
    *-------result----------- 
    Group Criteria
    --------------------------------
    New Onset Diabetes
    Long standing Diabetes                  
    */

    You could use the following sample.

    DECLARE @find varchar(200);
    SET @find ='Participant has a diagnosis of one of the following based on study definitions; -  ';
    SELECT LTRIM(REPLACE([Group Criteria],@find,'')) FROM yourTable

    Best Regards
    Puzzle
    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, October 19, 2018 9:15 AM
  • SELECT LTRIM(RTRIM(STUFF([Group Criteria],1,CHARINDEX('-',[Group Criteria]),''))) FROM TableName


    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    ----------------------------
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    Friday, October 19, 2018 7:00 AM
    Answerer

All replies

  • DECLARE @s1 varchar(200);
    --SET @s1 = 'Participant has a diagnosis of one of the following based on study definitions; -   New Onset Diabetes';
    SET @s1 = 'Participant has a diagnosis of one of the following based on study definitions; -  Long standing Diabetes';
    SELECT LTRIM(SUBSTRING(@s1, LEN('Participant has a diagnosis of one of the following based on study definitions; -   ') + 1, LEN(@s1) - LEN('Participant has a diagnosis of one of the following based on study definitions; -   ')));


    A Fan of SSIS, SSRS and SSAS

    Thursday, October 18, 2018 9:06 PM
    Answerer
  • SELECT LTRIM(RTRIM(STUFF([Group Criteria],1,CHARINDEX('-',[Group Criteria]),''))) FROM TableName


    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    ----------------------------
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    Friday, October 19, 2018 7:00 AM
    Answerer
  • Hi Ri1_2,

    According to your description, my understanding is that you want to SELECT part of the value in the column 'Group Criteria' like the following text. If anything is misunderstood, please tell me.

    *-------former----------- 
    Group Criteria
    --------------------------------
    Participant has a diagnosis of one of the following based on study definitions; -  New Onset Diabetes
    Participant has a diagnosis of one of the following based on study definitions; -  Long standing Diabetes                  
    */
    
    *-------result----------- 
    Group Criteria
    --------------------------------
    New Onset Diabetes
    Long standing Diabetes                  
    */

    You could use the following sample.

    DECLARE @find varchar(200);
    SET @find ='Participant has a diagnosis of one of the following based on study definitions; -  ';
    SELECT LTRIM(REPLACE([Group Criteria],@find,'')) FROM yourTable

    Best Regards
    Puzzle
    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Friday, October 19, 2018 9:15 AM