Muhammad Dody Suhada Muhammad Dody Suhada - 1 year ago 58
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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download