Q:

Change date to string

I have this code
select Key
      ,CAST(LEFT(CAST(Key as nvarchar(8)),4)+'0101' as int) as YearaFirstKey
FROM DimDt WHERE Key > 0

I need to change this code to string = cStr() , int as cInt(), use substring mid(). But I don't know how. If I print out the code, it shows this:

A:

 SELECT [key], CONVERT(varchar(30), CAST([key] as datetime), 103) as strDate

with your format code chosen from 
https://www.w3schools.com/sql/func_sqlserver_convert.asp
+++++
your date is in iso format as a string, so it is simple to change it to a date type, then format the date type using built in SQL functions

