Created
June 20, 2022 20:55
-
-
Save jingyang-li/327de12c1d15dec6b8cbd2b15883e250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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