[Solved] Convert month and year columns to a date column with additional string concatination


Assuming your are using date and MSSQL2012+:

SELECT  UPPER( FORMAT(CONVERT(datetime, '2017-02-01',121),'MMM')) + '-' +RIGHT(CAST( YEAR( CONVERT(datetime, '2017-02-01',121)) AS VARCHAR(4)),2) M_DELIVERY
, 'DELIVERY FOR ' +UPPER( FORMAT(CONVERT(datetime, '2017-02-01',121),'MMM'))+' '+ CAST( YEAR( CONVERT(datetime, '2017-02-01',121)) AS VARCHAR(4)) AS Description

Other way(using numbers and not date):
(you can change months name abbrev.)

SELECT  SUBSTRING('GENFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC',1+(MONTH_NUMB-1)*3,3)+'-'+ RIGHT(YEAR_NUMB,2) AS M_DELIVERY
    , 'DELIVERY FOR ' + SUBSTRING('GENFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC',1+(MONTH_NUMB-1)*3,3)+' '+ CAST(YEAR_NUMB AS VARCHAR(4)) AS DESCRIPTION
    FROM /* sample data */ (SELECT 2 AS MONTH_NUMB, 2015 AS YEAR_NUMB
          UNION SELECT 12 AS MONTH_NUMB, 2017 AS YEAR_NUMB
          UNION SELECT 1 AS MONTH_NUMB, 2016 AS YEAR_NUMB) X

Output for the latter:

M_DELIVERY DESCRIPTION
---------- ---------------------
GEN-16     DELIVERY FOR GEN 2016
FEB-15     DELIVERY FOR FEB 2015
DIC-17     DELIVERY FOR DEC 2017

1

solved Convert month and year columns to a date column with additional string concatination