Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
FIR NO
DDR :14 US 174 CrPC
DDR :10 US 174 CrPC
DDR :42 US 174 CRPC
DDR :25 US 174 CrPC PS DARIYA
DDR :29



I want to following
FIR No       UnderSection
10          US 174 CrPC
14         US 174 CrPC
42         US 174 CrPC


What I have tried:

how to split data after fourth character in sql query 
Posted
Updated 28-Apr-21 19:55pm
v2

1 solution

Use the SUBSTRING[^] function:
SQL
SELECT SUBSTRING(MyTextColumn, 6, 2) AS [FIR No]
      ,SUBSTRING(MyTextColumn, 9, 9999) AS [Under Section]
FROM MyTable
 
Share this answer
 
Comments
Nishant.Chauhan80 29-Apr-21 2:00am    
but FIR No three digit showing only two digit like

FIR NO Showing

FIR:113 11
FIR:245 24

Showing only two digit when apply your query
OriginalGriff 29-Apr-21 2:23am    
so you will have to make it more complicated - your sample data shows two characters, and that's all I get to work with.

You will have to look very closely at your data and work out exactly what it can contain. Then use CHARINDEX to work out the column start and length values.

https://www.w3schools.com/sql/func_sqlserver_charindex.asp

I suspect that a couple of SQL user defined functions would be a good idea, but they'll probably be messy as well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900