Dealing with fixed width data:
Data in a fixed-width text file or string is arranged in rows and
columns, with one entry per row. Each column has a fixed width,
specified in characters, which determines the maximum amount of data
it can contain. No delimiters are used to separate the fields in the
file.
Parsing that data in T-SQL you can use SUBSTRING
https://learn.microsoft.com/en-us/sql/t-sql/functions/substring-transact-sql?view=sql-server-2017
SUBSTRING ( expression ,start , length )
Here's an example:
DECLARE @SampleData TABLE
(
[LineData] NVARCHAR(255)
);
INSERT INTO @SampleData (
[LineData]
)
VALUES ( '1001RJOHNKEITH25 20181017 NA' )
, ( '1002CDWANEKANE36 20181010 RR' )
, ( '1003CMIKAYLAGN44 20181011 RR' );
SELECT SUBSTRING([LineData], 1, 4) AS [PersonId]
, SUBSTRING([LineData], 5, 1) AS [Indicator]
, SUBSTRING([LineData], 6, 9) AS [Name]
, SUBSTRING([LineData], 15, 2) AS [Age]
, SUBSTRING([LineData], 18, 8) AS [RegDate]
, SUBSTRING([LineData], 27, 2) AS [RecordType]
, *
FROM @SampleData;
So in your example you're wanted to evaluate whether or not the "Indicator" is 'R', you can get to that value with:
SUBSTRING([LineData], 5, 1)
Not sure how that fits into what you have been tasked with. Based on other comments there's more to how this "Indicator" is determined.
Not ideal, but you could parse out all the fields and then put them back together doing the evaluation on that indicator field or use stuff in a case statement to replace the date with blanks when evaluating if indicator is R in the string.
DECLARE @SampleData TABLE
(
[LineData] NVARCHAR(255)
);
INSERT INTO @SampleData (
[LineData]
)
VALUES ( '1001RJOHNKEITH25 20181017 NA' )
, ( '1002CDWANEKANE36 20181010 RR' )
, ( '1003CMIKAYLAGN44 20181011 RR' );
--We check for R using substring
--when not equal to R we replace where Registration date in the string was with blanks.
SELECT CASE WHEN SUBSTRING([LineData], 5, 1) = 'R' THEN [LineData]
ELSE STUFF([LineData], 18, 8, ' ')
END AS [LineData]
FROM @SampleData;