How to deselect values in multivalue lookup field using a query - sql

I want to delete all the data of a single field. This field is a ''multipled value lookup field'';
I tried this query in the SQL design tab:
UPDATE _myDatabase SET [_myDatabase].mycolumn= Null;
but it's not working (although it works for a any non-lookup fields). Any idea how to solve this?

Because you are using a multi value field, you must treat the field as a separate table, which it actually is under the hood.
So you use a DELETE statement:
DELETE _myDatabase.mycolumn.Value FROM _myDatabase

Related

How to update a sql record text, by replacing a string for various text?

I have to update a table record where I am replacing some old email ids with a new id.
I am at the moment doing replace like
replace(replace(replace( column, 'abd#xyz.com', 'new#email.com),'old#re.com', 'new#email.com'),'asda#sdfsd.f', 'new#email.com')
Is there any simple way to do it?
I am not sure why a column would contain an email and other information. So perhaps this does what you want:
update t
set column = 'new#email.com'
where column in ('abd#xyz.com', 'old#re.com', 'asda#sdfsd.f');
If the column contains additional information, I would recommend that you fix your data model rather than trying to make a broken data model work.

view unique values in Combobox using VBA in MS Access

please read my question to end because I test all previous solutions in Stackoverflow and have no answer.
I am trying to display Combobox in the form of an MS Access database using VBA, this Combobox takes its values from one table the problem that I can't display just unique values, Combobox views all values even when I use DISTINCT still view all.
also, I am trying to use GROUP BY but not work.
I know it is a simple problem but how can I solve it?
SELECT DISTINCT Exports_imports_Table.ID, Exports_imports_Table.content FROM Exports_imports_Table;
Assuming the ID field is a unique value (and the content field may have duplicates) you cannot include it in a DISTINCT. Try it like this
SELECT DISTINCT Exports_imports_Table.content FROM Exports_imports_Table;
Does that give you what you expect?
Don't take the ID field in your query builder. Instead of that, select the same field twice, leaving one of them as is, and in another you can give your conditions or formats (if any).
Make sure to change unique values in general properties to "yes".
Save it, and there you are.

Multiplying 2 value in database

I have a database. I created it with HeidiSQL. Its look like this.
I enter the value-1 and value-2.
Is there a way to enter a formula to Result column like " =Value-1 * Value-2 " ? I want my database to calculate the Result when I enter my values to other cells.
A trigger is one way to achieve automated column content.
A second one is a view, which you can create additionally to the table. That view could contain SQL which generates the result:
SELECT value1, value2, value1*value2 AS result
A third (more modern) alternative is adding a virtual column in your existing table. You can do that with HeidiSQL's table editor, like shown in the screenshot. Just add a new column with INT data type, and set its Virtuality to "VIRTUAL", and Expression to "value-1 * value-2". That's it.
I'm not familiar with HeidiSQL, but it appears to be a front end? What RDBMS are you using, for example SQL Server allows a computed column.
SQL
ALTER TABLE YourTable
ADD Result AS ([Value-1] * [Value-2])
Right click your database name in the folder structure, go to --> create new then -->Trigger
Then you can create a trigger that when entering data, will be activated on the entire column like this:
But you will need to know how to write the actual query and function. This requires basic knowledge that is generally generic and consistent of most all SQL languages.

Pulling field names from SQL query

Is there a way to retrieve the field names from an actual query, similar to how you can retrieve field names from a table using the INFORMATION_SCHEMA? In essence, I'm wanting to accept an entire query as a parameter, and be able to build an empty table with the field names from said query.
Right now, I'm using a STUFF() function to replace the SELECT with SELECT TOP 1 and replacing the FROM with a INTO tablename FROM, and then truncating tablename. It works, but I need this to be able to handle complex queries where the first occurrence of FROM might not be the one I need (in case the user is using a subquery for a field, for example).

query a table not in normal 3rd form

Hi I have a table which was designed by a lazy developer who did not created it in 3rd normal form. He saved the arrays in the table instead of using MM relation . And the application is running so I can not change the database schema.
I need to query the table like this:
SELECT * FROM myTable
WHERE usergroup = 20
where usergroup field contains data like this : 17,19,20 or it could be also only 20 or only 19.
I could search with like:
SELECT * FROM myTable
WHERE usergroup LIKE 20
but in this case it would match also for field which contain 200 e.g.
Anybody any idea?
thanx
Fix the bad database design.
A short-term fix is to add a related table for the correct structure. Add a trigger to parse the info in the old field to the related table on insert and update. Then write a script to [parse out existing data. Now you can porperly query but you haven't broken any of the old code. THen you can search for the old code and fix. Once you have done that then just change how code is inserted or udated inthe orginal table to add the new table and drop the old column.
Write a table-valued user-defined function (UDF in SQL Server, I am sure it will have a different name in other RDBMS) to parse the values of the column containing the list which is stored as a string. For each item in the comma-delimited list, your function should return a row in the table result. When you are using a query like this, query against the results returned from the UDF.
Write a function to convert a comma delimited list to a table. Should be pretty simple. Then you can use IN().