Get character after spaces

Hi

How can I get the first character after 6 spaces using a derived column

so for example the f from this string
Net change in unrealized gain/(loss) on foreign currency translations

and the d from this one
Net change in unrealized gain/(loss) on derivatives

I would try using STRING_SPLIT in the SQL if possible:

DECLARE @String VARCHAR(250)
SET @String='Net change in unrealized gain/(loss) on derivatives'

;WITH Words AS
(
SELECT * FROM STRING_SPLIT(@String,' ',1)
)
SELECT LEFT(value,1)
FROM Words
WHERE ordinal=7

If you really want to use a derived column, you can use TOKEN and LEFT

TOKEN (SSIS Expression) - SQL Server Integration Services (SSIS) | Microsoft Learn


;WITH cte_data AS (
    SELECT 'Net change in unrealized gain/(loss) on foreign currency translations' AS string
    UNION ALL
    SELECT 'Net change in unrealized gain/(loss) on derivatives'
    UNION ALL
    SELECT 'Something went wrong with input'
)
SELECT SUBSTRING(string, s6.space + 1, 1) /*,  string*/
FROM cte_data
CROSS APPLY ( SELECT NULLIF(CHARINDEX(' ', string), 0) AS space ) AS s1 
CROSS APPLY ( SELECT NULLIF(CHARINDEX(' ', string, s1.space + 1), 0) AS space ) AS s2 
CROSS APPLY ( SELECT NULLIF(CHARINDEX(' ', string, s2.space + 1), 0) AS space ) AS s3 
CROSS APPLY ( SELECT NULLIF(CHARINDEX(' ', string, s3.space + 1), 0) AS space ) AS s4 
CROSS APPLY ( SELECT NULLIF(CHARINDEX(' ', string, s4.space + 1), 0) AS space ) AS s5 
CROSS APPLY ( SELECT NULLIF(CHARINDEX(' ', string, s5.space + 1), 0) AS space ) AS s6

Hi

Hope this helps

You will need SQL Server 2012 ( for String Split Ordinal Position )

create sample data

drop table #temp
create table #temp ( String varchar(max) )
insert into #temp
SELECT 'Net change in unrealized gain/(loss) on foreign currency translations' AS string
UNION ALL
SELECT 'Net change in unrealized gain/(loss) on derivatives'
UNION ALL
SELECT 'OK fine Do you feel good Thanks Nope Sure '

SELECT
   string 
   , left(value,1) 
FROM
   #temp 
      cross apply 
   string_split(String,' ',1)
WHERE 
   ordinal = 7

image