How to get the 1st value before delimiter in sql server

后端 未结 3 1199
情书的邮戳
情书的邮戳 2021-01-01 16:32

In one of the column i am getting 2 values with a delimiter between it How to extract both the values

I have some thing like this Column TRN02 is

相关标签:
3条回答
  • SELECT LEFT(details, CHARINDEX ('-', TRN02 ) - 1),
           SUBSTRING(details, CHARINDEX ('-', TRN02 ) + 1, 100) 
      FROM Your_table
    
    0 讨论(0)
  • 2021-01-01 16:39

    You can use SUBSTRING to do this:

    SELECT 
        SUBSTRING(TRN02, 0, CHARINDEX('-', TRN02)) AS [First]
        SUBSTRING(TRN02, CHARINDEX('-', TRN02)  + 1, LEN(TRN02)) AS [Second]
    FROM TABLE
    
    0 讨论(0)
  • 2021-01-01 16:59

    Just another way USING LEFT and RIGHT -

    SELECT LEFT(TRN02, CHARINDEX('-', TRN02) - 1) [before_delim],
           RIGHT(TRN02, LEN(TRN02) - CHARINDEX('-', TRN02)) [after_delim]
    FROM your_table
    
    0 讨论(0)
提交回复
热议问题