Skip to content
Advertisement

How to get first character-set of string in sql?

SELECT SUBSTRING('202500 135000', 1, 7) AS ExtractString;
SELECT SUBSTRING('37500 25000', 1, 5) AS ExtractString;

I want to get 202500 and 37500 without not adding removed characters (in eg: 7, 5). (ie. first string gp in columns).sample-image description here But, I don’t know to get string in front of blank string “”. I have a little exp in sql. pls show me ans.

Advertisement

Answer

Use SUBSTRING_INDEX instead

SELECT SUBSTRING_INDEX('202500 135000', " ", 1) AS ExtractString;
SELECT SUBSTRING_INDEX('37500 25000', " ", 1) AS ExtractString;
| ExtractString |
| :------------ |
| 202500        |

| ExtractString |
| :------------ |
| 37500         |

db<>fiddle here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement