-2

I have value like

b10F|b3432R|b2134D

I need to get only the first value before the pipe:

b10F

How can I do that?

  • Have you reviewed the numerous string functions available in your specific RDBMS? – Stu Apr 20 '22 at 08:41
  • 1
    You really need to reveal the exact SQL _database_ you are using (e.g. MySQL, SQL Server, Oracle, Postgres, etc.). Every database has its own peculiar string API. – Tim Biegeleisen Apr 20 '22 at 08:41
  • Does this answer your question? [Split string on only first occurance of character/delimiter](https://stackoverflow.com/questions/13430905/split-string-on-only-first-occurance-of-character-delimiter) – ikweethetniet Apr 20 '22 at 09:02
  • Even more duplicates can be found with a simple [search](https://www.google.com/search?q=Get+first+delimiter+VALUE+sql+server+site:stackoverflow.com). – Thom A Apr 20 '22 at 09:07

2 Answers2

0

use mysql query with SUBSTRING_INDEX

SELECT SUBSTRING_INDEX("b10F|b3432R|b2134D", "|", 1)
Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39
0

Maybe use this query which uses CHARINDEX function to find the location of first pipe character and then uses LEFT to get data till that position -1

 SELECT 
      LEFT(
             'b10F|b3432R|b2134D',
              CHARINDEX('|', 'b10F|b3432R|b2134D' ) -1 
          )AS Output;

    
DhruvJoshi
  • 17,041
  • 6
  • 41
  • 60