Can ARRAY_CONTAINS accept multiple values in Cosmos - azure

Do you have sample if i want to match multiple values of one attribute in Array_contains
select * from c where c.sid="1" and c.unum=39 and ARRAY_CONTAINS (c.dcodes,"DIST,DEFT")
where dcodes is my array having just list of codes in my document. so i want to pull all the records for the dcodes i passed into the query it may be one or many.

You're currently just passing a single string. You need to pass an array of values as your first parameter to ARRAY_CONTAINS(). So in your case, if you wanted to select all documents whose property c.dcodes contains either "DIST" or "DEFT", you'd need to do something like:
SELECT *
FROM c
WHERE c.sid="1" and c.unum=39
AND ARRAY_CONTAINS (["DIST","DEFT"],c.dcodes)

Related

Trying to create a NetSuite saved search where the result is a single row, single column containing the actual result Internal IDs

Let's say I create a saved search where the criteria returns 10 records. Is there any way that what I can manipulate the results so I receive a single row, and a single column,containing an array or list of the Internal IDs of that search?
It sounds like what you want is NS_CONCAT()
Add a Formula(text) to your search results. Set Summary Type to Minimum or Maximum. Use the formula NS_CONCAT({internalid}). Remove any other columns (rows in the Results tab).

query does not include the specified expression 'ColB' as part of an aggregate function

I am using this query and it is working perfect but in excel as a database, it is giving me an error of aggregate function -
solution: once I add all column in the group by I don't get sum and Group by doesn't work.
select ColA,ColB,ColC,ColdD,SUM(ColE),ColF,ColG FROM automate GROUP BY ColA
One picture indicates table structure:
Another one is expected output:
Please help me if someone knows- MS-Access / excel as database
Every field in your SELECT part must be either GROUPed BY or aggregated. If all values are guaranteed to be the same or if you don't care which value will be picked use FIRST(), otherwise use the appropriate aggregate function (MIN, MAX, FIRST, LAST, SUM, etc.)
Example:
SELECT ColA, FIRST(ColB), FIRST(ColC), FIRST(ColdD), SUM(ColE), FIRST(ColF), FIRST(ColG) FROM automate GROUP BY ColA

passing variables in cur.executescript

Currently I have the following code which checks if tablename "Company" exists in the database, and then creates the table with the given fields.
cur.executescript('''
DROP TABLE IF EXISTS Company;
CREATE TABLE Company (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
name VARCHAR2
)
''')
I want to make this query generic as in, instead of just using "Company" in my query, I need to take the names from a list. Is it possible to pass a variable in the query instead of passing "Company" in this example.
Thank you!
It is not possible to pass a variable table name (or column name) to sqlite. (And since executescript takes exactly one argument, it's not possible to pass a variable to executescript).
You could build the query before the execute and pass that variable to executescript.
And of course if you take the table names from a list, it seems likely you will have to take the column names too!

CRecordset::IsFieldNull method replacement in bulk row fetching

I have query related to bulk row fetching using CRecordSet (MFC ODBC).
On the MSDN page, it is written that
The member functions IsDeleted, IsFieldDirty, IsFieldNull, IsFieldNullable, SetFieldDirty, and SetFieldNull cannot be used on recordsets that implement bulk row fetching. However, you can call GetRowStatus in place of IsDeleted, and GetODBCFieldInfo in place of IsFieldNullable.
Now, I want to check whether a field contains "NULL"/"has no value" data. How can I check this as the IsFieldNull function does not work in bulk row fetching?
There is the difference between IsFieldNull and IsFieldNullable function.
So logically you will not be able to know whether a filed is null for a particular row since you are doing bulk row fetching. But you can only determine whether a particular field is nullable which simply means if that field is capable of accepting null values.
The CODBCFieldInfo structure contains information about the fields in an ODBC data source.
It has a member called m_nNullability which identifies Whether the field accepts a Null value. This can be one of two values: SQL_NULLABLE if the field accepts Null values, or SQL_NO_NULLS if the field does not accept Null values.
So pass the object of CODBCFieldInfo structure to CRecordset::GetODBCFieldInfo function which collects the object by reference. So no need to worry, you will get the updated value back and then check the member m_nNullability value of that object to only know whether the filed is nullable and not whether a field for a particular row is null.
http://msdn.microsoft.com/en-us/library/xexc6xef(v=vs.80).aspx
http://msdn.microsoft.com/en-us/library/k50dcc9s(v=vs.80).aspx
CRecordset::GetODBCFieldInfo function has two versions. One version of the function lets you look up a field by name. The other version lets you look up a field by index.

How do I create an index in PostgreSQL based on lowercase only?

How would I set up an index based on lower case only?
Even though the actual field contains both upper and lower case letters.
Also, can I run a query and have only the lower case index value returned?
You can create the index and transform the field to upper- or lower-case. Then when you do your queries, you can do the same transform and it'll do the right thing.
So:
CREATE UNIQUE INDEX lower_case_username ON users ((lower(username)));
Then query for the same thing:
SELECT username FROM users WHERE lower(username) = 'bob';
According to the docs you can do this:
CREATE UNIQUE INDEX lower_title_idx ON films ((lower(title)));
You can also use this for wildcard searches:
CREATE INDEX IF NOT EXISTS foo_table_bar_field ON foo_table(lower(username))
Query like so:
SELECT * FROM foo_table WHERE lower(username) like 'bob%'
CREATE UNIQUE INDEX my_index_name ON my_table (LOWER(my_field));

Resources