beginerdeveloper
beginerdeveloper

Reputation: 845

azure Mobile app query like sql Statement

I am working with Azure Mobile app and here is my SQL statement

return new Promise((resolve, reject) => {
        var query = {
            sql: "SELECT Id FROM Groups WHERE Members LIKE '%@userId%' and Members '%@friendId%' and type = @roomType ",
            parameters: [
                { name: 'userId', value: userId},
                { name: 'friendId', value: friendId },
                { name: 'roomType', value: type }
            ]
        };    

        context.data.execute(query)
            .then(function (results) {
                resolve(results);
            }).catch(error => { reject (error);});
    });

and I go to SQL and fill all variable like this

SELECT Id FROM Groups Where Members LIKE '%05adf56b-c128-4203-802f-d8d0e2916210%' and Members LIKE '%21B69402-7E9C-4BA3-99A8-6D84A96FA866%' and type = 0 

and i got many records. so i didn't know what i did wrong

Upvotes: 0

Views: 100

Answers (1)

Bruce Chen
Bruce Chen

Reputation: 18465

It seems that your SQL statement looks incorrect, you may miss a like keyword for Members '%@friendId%'.

I have tested the following SQL statement on my azure mobile app, it returns nothing.

SELECT Id FROM Groups WHERE Members LIKE '%@userId%'

After some trials, I found the following statement could work as expected:

var query = {
   sql: "SELECT * FROM test5 where name LIKE @name",
   parameters: [
     {name:"name",value:"%"+req.query.param1+"%"}
   ]
};

SELECT Id FROM Groups Where Members LIKE '%05adf56b-c128-4203-802f-d8d0e2916210%' and Members LIKE '%21B69402-7E9C-4BA3-99A8-6D84A96FA866%' and type = 0

and i got many records. so i didn't know what i did wrong

Based on your description, it seems that your Members column contains many GUIDs. You need to check your table records by yourself, or you could update your question with more details about your records for us to narrow down this issue.

Upvotes: 1

Related Questions