I have a table called Register
Id, Type_status, Status, Description
Example:
ID Type_status Status Description
1 8000 8017 test
And i have a table called History with the following structure
Id, Id_Register, History_status, Payload
Example
Id Id_Register History_status Payload
1 1 8015 {"name": "test"}
2 1 8016 {"token": "example"}
3 1 8017 {"email": "test@test.com"}
What I need is to be able to execute a query that will bring me the value of Record_Id
and Payload
value from the History table when the Id_Register = 1
and the History_status
is 8015
and 8017
with History_status
8017 is email = test@test.com
The expected result is
Id_Register Name Token
1 test. example
I need to get all the names and token of the records that in the 8017 state have as email test@test.com
Mention that I have already solved the comparison of the text in the json, what I could not achieve is the query to obtain the two values for the same table depending on the states that I mention.
JSON_VALUE(cast(Payload as nvarchar(max)), '$.email') LIKE '%test@test.com%'