简体   繁体   中英

How can I write a compound WHERE condition using documentdb?

I have a document that looks like this:

{
  "email": "joan.smith@somedomain.com",
  "name": {
    "first": "Joan",
    "last": "Smith"
  }
}

How can I write a SQL query that uses a compound comparison against the entire last name?

This is effectively what I'd like to do in the WHERE:

SELECT * 
FROM c 
WHERE c.name.first + " " + c.name.last = "Joan Smith"

The "plural" version

SELECT * 
FROM c 
WHERE c.name.first + " " + c.name.last 
  IN ("Joan Smith", "Juan Suarez")

Both of these queries will run in the Azure Portal without error, but they return empty results. I have tried wrapping the concatenation in parentheses but this has no effect.

According to the Cosmos DB SQL APIs , if you want to implement concatenation in Cosmos DB SQL, you need to use || instead of + .

So, please modify your sql as below:

SELECT c.id,c.name 
FROM c 
WHERE c.name.first || " " || c.name.last = "Joan Smith"

Then you could get the results you want.

在此处输入图片说明

Hope it helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM