Home > Back-end >  How to remove the first word from a large string
How to remove the first word from a large string

Time:12-13

I want to remove the first word from a large string in SQL Server.

Input string:

931078027 BP 16:20:0:13 25 BAG 'B' CLASS

Desired output:

BP 16:20:0:13 25 BAG 'B' CLASS

CodePudding user response:

You may use a substring operation, e.g.

WITH yourTable AS (
    SELECT '931078027 BP 16:20:0:13 25 BAG ''B'' CLASS' AS val
)

SELECT val,
       SUBSTRING(val,
                 CHARINDEX(' ', val)   1,
                 LEN(val) - CHARINDEX(' ', val)) AS val_out
FROM yourTable;

Demo

CodePudding user response:

Declare @val Varchar(50) ='931078027 BP 16:20:0:13 25 BAG ''B'' CLASS'
SELECT REPLACE(@val, '931078027', '')
  • Related