locked
Get Record After First Space RRS feed

  • Question

  • User-807418713 posted

    Hello

    This is my column1 data

    AA hello
    KLM YES
    NNN VERY GOOD
    HF BEST

    I want outplut like this after space data

    hello

    Yes

    VERY GOOD

    BEST

    Wednesday, December 23, 2020 7:18 AM

Answers

  • User753101303 posted

    Hi,

    If using SQL Server it could be something such as :

    create table tmp(value varchar(20))
    insert into tmp(value) values ('AA hello'),('KLM YES'),('NNN VERY GOOD'),('HF BEST'),('AAA')
    go
    select substring(value,charindex(' ',value),LEN(value)+1) from tmp

    See String Functions (Transact-SQL) - SQL Server | Microsoft Docs for all string functions.

    Edit: I'm using the fact that CHARINDEX(' ',value) returns 0 if a string is not found, and that substring starts from 1 but does take the start index to get enough characters so LEN(value)+1 ensure all is taken to the end even if CHARINDEX(' ',value) returns 0.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 23, 2020 10:21 AM