view raw
Muhammad Dody Suhada Muhammad Dody Suhada - 8 months ago 28
SQL Question

How can I convert this query result to date format (SQL Server)

This for example :

concat (concat('201', (substring('A41020', 2, 1)), '-', (substring('B210906', 6, 2))

and the result is 2014-06.

What additional query I can use to change this string (2014-06) to date format while I retrieve the data?

For now, I have to change cell format in Excel when I am using data from this query.

Help me master


Use the below i have set the date as 01,which you can change as per your requirement. Also you can use CONVERT or CAST function in this situation.

SELECT CONVERT(datetime,'201'+substring('A41020', 2, 1)+'-'+substring('B210906', 6, 2)+'-01')


SELECT CAST(('201'+substring('A41020', 2, 1)+'-'+substring('B210906', 6, 2)+'-01')as  datetime)

enter image description here