I want output like this. I want to extract date part and rig part in two different column.
DATASOURCE | MatchPlodDate | MatchRigNo |
---|---|---|
Setos Zradow plod 01-10-21 Rig 1 DS and NS.xlsm | 01-10-21 | Rig 1 |
ZNOZ PN plod 01-2-22 Rig 6 DS and NS.xlsm | 01-2-22 | Rig 6 |
Xlenuteq plod 1-11-21 Rig 2 DS and NS.xlsm | 1-11-21 | Rig 2 |
FdinSetals plod 1-1-22 Rig 3 DS and NS.xlsm | 1-1-22 | Rig 3 |
DROP TABLE IF EXISTS #aaa_Test_hours;
CREATE TABLE #aaa_Test_hours (
[DataSource] VARCHAR(500) NULL
);
INSERT INTO #aaa_Test_hours
VALUES (
'Setos Zradow plod 01-10-21 Rig 1 DS and NS.xlsm'
)
,(
'ZNOZ PN plod 01-2-22 Rig 6 DS and NS.xlsm'
)
,(
'Xlenuteq plod 1-11-21 Rig 2 DS and NS.xlsm'
)
,(
'FdinSetals plod 1-1-22 Rig 3 DS and NS.xlsm'
);
SELECT DATASOURCE,SUBSTRING(DataSource, CHARINDEX('plod',DataSource) + LEN('plod')+1, 8) as [MatchPlodDate]
,LEFT(DATASOURCE,CHARINDEX('DS',DataSource)-1) as [MatchRigNo]
FROM #aaa_Test_hours
Currently my output is coming like this, which is not correct. I don't know how I fixed my SQL code.
DATASOURCE | MatchPlodDate | MatchRigNo |
---|---|---|
Setos Zradow plod 01-10-21 Rig 1 DS and NS.xlsm | 01-10-21 | Setos Zradow plod 01-10-21 Rig 1 |
ZNOZ PN plod 01-2-22 Rig 6 DS and NS.xlsm | 01-2-22 | ZNOZ PN plod 01-2-22 Rig 6 |
Xlenuteq plod 1-11-21 Rig 2 DS and NS.xlsm | 1-11-21 | Xlenuteq plod 1-11-21 Rig 2 |
FdinSetals plod 1-1-22 Rig 3 DS and NS.xlsm | 1-1-22 R | FdinSetals plod 1-1-22 Rig 3 |
any help what i am doing wring in my SQL code???