Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jingyang-li/327de12c1d15dec6b8cbd2b15883e250 to your computer and use it in GitHub Desktop.
Save jingyang-li/327de12c1d15dec6b8cbd2b15883e250 to your computer and use it in GitHub Desktop.
Create table test(id INT, dates VARCHAR(200))
INSERT INTO test (id, dates)
VALUES (1001, '5,10,15,20,25')
, (1002,'9,12,12,25,30')
Declare @GivenMonth varchar(8)='JUN-2022'
;with mycte as (
select id ,'['+ dates +']' jsondates
from test)
select id,try_Convert(date, c.value+'-'+ @GivenMonth ,103) dates
from mycte
CROSS APPLY OPENJSON(jsondates) AS c
Drop table test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment