Ali
Ali

Reputation: 99

SQL Server where Clause on JSON Field

I have a table

ID |  Start Date       | End Date          | Summary
---+-------------------+-------------------+----------------------------
1  | 2020-01-01T09:20  | 2020-01-01T09:30  | {"total":20,"totalError":10}
1  | 2020-01-02T09:20  | 2020-01-02T10:55  | {"total":10,"totalError":5}

I want to query where totalError > 0

Select * 
from runLog 
where Summary.totalError > 0

Is this possible?

Upvotes: -1

Views: 1377

Answers (1)

GMB
GMB

Reputation: 222432

Use JSON_VALUE():

select * from runLog where json_value(summary, '$.totalError') > 0

Upvotes: 2

Related Questions