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;
-
I removed that tags for Postgres and Oracle as this is clearly (only) for SQL Serveruser1822– user18222019年07月31日 07:43:29 +00:00Commented Jul 31, 2019 at 7:43
1 Answer 1
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!
answered Jul 31, 2019 at 7:46
-
Thanks its workingPrabin Swain– Prabin Swain2019年07月31日 07:49:13 +00:00Commented Jul 31, 2019 at 7:49
-
@PrabinSwain Then you should mark this answer correct.Rajesh Ranjan– Rajesh Ranjan2019年07月31日 07:51:47 +00:00Commented 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.Prabin Swain– Prabin Swain2019年08月22日 06:00:18 +00:00Commented Aug 22, 2019 at 6:00
lang-sql