SQL Server Datetime comparision with JSON is not working

yfjy0ee7  于 2023-10-15  发布在  其他
关注(0)|答案(1)|浏览(72)

I have a SQL table with JSON data. JSON has a property with value '2023-10-05T22:34:13.7944869+00:00'. In my SQL where clause if I write below code it doesn't return any records.

JSON_VALUE( myrow.Value,'$.Date') 
BETWEEN '2023-10-05 00:00:00' AND '2023-10-05 23:59:59')

However if I change the date in the where clause to 6th Oct like below it returns records.

JSON_VALUE( myrow.Value,'$.Date') 
BETWEEN '2023-10-05 00:00:00' AND '2023-10-06 23:59:59')

As JSON has 5th Oct date why first condition is not returning data.

kxeu7u2r

kxeu7u2r1#

This solved my issue.

CONVERT(datetime2,JSON_VALUE( myrow.Value,'$.Date'),126)

相关问题