Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to check data with in a json string exists or not exists in a table .
I am passing a json string which contains reference no: I am using Sql server 2008.

json string is as below:
{"Login_Id":"alex.maker","User_Name":"Samuel Jacob","Email_Id":"Samuel.Jacob@nestgroup.net","Mode":"M","Corporate_ID":"NeST","Establishment_ID":"12345678911830098344779998855552331","Reference_No":"IB120219100105"}'

What I have tried:

Tried as below:
declare @ReferenceNo varchar(max) ='IB120219100105'
set @ReferenceNo='{"Login_Id":"alex.maker","User_Name":"Samuel Jacob","Email_Id":"Samuel.Jacob@nestgroup.net","Mode":"M","Corporate_ID":"NeST","Establishment_ID":"12345678911830098344779998855552331","Reference_No":"IB120219100105"}'

SELECT * FROM User_Sync_Log WHERE  
SyncLogRequest LIKE   '%Reference_No": "%'+@ReferenceNo+'"%'

But no data coming
Posted
Updated 27-May-19 20:56pm
v4
Comments
Kornfeld Eliyahu Peter 28-May-19 1:36am    
It is not validation (that would be a syntax check), but actually using the data from within SQL...
What version of SQL do you have?
ranio 28-May-19 1:53am    
sql server 2008
Richard Deeming 29-May-19 11:14am    
Are you sure you have a record in your table where the SyncLogRequest column matches the pattern:
'%Reference_No": "%{"Login_Id":"alex.maker","User_Name":"Samuel Jacob","Email_Id":"Samuel.Jacob@nestgroup.net","Mode":"M","Corporate_ID":"NeST","Establishment_ID":"12345678911830098344779998855552331","Reference_No":"IB120219100105"}"%


NB: You've overwritten the @ReferenceNo variable immediately after declaring it. I don't think you meant to do that.

1 solution

Before 2016 there is nothing built in you can use... You have to write your own JSON parsing functions in SQL...
There is a good sample here to start with:
Consuming JSON Strings in SQL Server - Simple Talk[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900