0

My Query is

declare @id INT
set @id = 69
select 
   (JSON_VALUE(cast(ad.data_map as varchar(max)),'$.dataMap."69".value')) CorrespondanceNumber,
   (JSON_VALUE(cast(ad.data_map as varchar(max)),'$.dataMap.***"@id"***.value')) Agency,
   (JSON_VALUE(cast(ad.data_map as varchar(max)),'$.dataMap."69".value')) Protocal
from actions_new a
  left join action_data ad on ad.id_ref = a.id
where baid = 12;
1
  • I removed that tags for Postgres and Oracle as this is clearly (only) for SQL Server Commented Jul 31, 2019 at 7:43

1 Answer 1

0

You should cast @id to varchar and concate it. like this.

(JSON_VALUE(cast(ad.data_map as varchar(max)),'$.dataMap.***"'+cast(@id as varchar)+'"***.value')) Agency,

Complete query is. Hope this will help you.

declare @id INT
set @id = 69
select 
(JSON_VALUE(cast(ad.data_map as varchar(max)),'$.dataMap."69".value')) CorrespondanceNumber,
(JSON_VALUE(cast(ad.data_map as varchar(max)),'$.dataMap.***"'+cast(@id as varchar)+'"***.value')) Agency,
(JSON_VALUE(cast(ad.data_map as varchar(max)),'$.dataMap."69".value')) Protocal
from actions_new a
left join action_data ad on ad.id_ref = a.id
where baid = 12;

Thanks!

3
  • Thanks its working Commented Jul 31, 2019 at 7:49
  • @PrabinSwain Then you should mark this answer correct. Commented Jul 31, 2019 at 7:51
  • +cast(@id as varchar)+ not working sql server 2016 error throughout The argument 2 of the "JSON_VALUE or JSON_QUERY" must be a string literal. Commented Aug 22, 2019 at 6:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.