在SQL Server 2016中的where子句中读取json值

时间:2018-12-12 07:37:58

标签: sql-server sql-server-2016

insert into #users(userid)
select userid
From maintableA
Inner join
(
    Select id 
    from maintable
    where  user_id=@createdby
) B  
    on A.id=B.id

@createdby参数包含具有以下结构的JSON数据:

  

{用户:{“创建者”:“ 23”}}

如何从此JSON中获取“ createdby”的值?

1 个答案:

答案 0 :(得分:0)

您可以使用内置的JSON_VALUE函数:

23

结果:insert into #users(userid) select userid From maintableA Inner join ( Select id from maintable where user_id = JSON_VALUE(@createdby, '$.User.createdby') ) as B on A.id=B.id

因此,您的代码如下所示:

let historyRef = ref.child("history")
let riderRef = ref.child("Users/Riders").child(riderID).child("history")
let driverRef  = ref.child("Users/Drivers").child(driverID).child("history")

let key = historyRef.childByAutoId().key
historyRef.child(key).setValue(true) 
riderRef.child(key).setValue(true) 
driverRef.child(key).setValue(true)