How do I populate a MS Access Query with a value of a Text Box - sql

I have two properties and each property has it's own table for orders. So I am trying to generate a query to show me all the orders for the property that is select from a text box.
So the query is as follows:
Select * from Orders_Property1
This query works.
However, I now want the query to return the result based on the property selected on a text box. I trying:
Select * from [Forms]![frm_ORDERS]![txt_PROPERTY]
I am getting a Syntax error. Any idea where I am going wrong?

You can't do that.
Fields and tables must be static in Access SQL.

Related

SQL: How to select data from column that does not end in 'EW'?

I have two identical tables on my web site, one table will show data where a certain column has a variable with the last letters are 'EW'. The code I am using for that is SELECT * FROM dry_mix WHERE note NOT LIKE '%EW';.
What I am trying to do now is fill my other table with data that does not end in 'EW'. I have tried the following code SELECT * FROM dry_mix WHERE note NOT LIKE '%EW'; but that is not working. Can anyone show me the correct way for me to write the code?
The correct syntax in most SQL variants would be:
SELECT * FROM dry_mix WHERE NOT(note LIKE '%EW');

Why The Query Against HashKey returns no records

I am working on a new sql table. The table has a column [varbinary(8000)], where we are storing hash of a certain text. Now, I am trying to retrieve the same record back by using a where clause against the hashkey, but that yields zero records.
I have added a similar query here: http://sqlfiddle.com/#!18/be996/11
Try without the single quotes, like this
SELECT id, description
FROM ForgeRock
where id = 0x94EE059335E587E501CC4BF90613E0814F00A7B08BC7C648FD865A2AF6A22CC2
and you will get the expected result.

Creating a calculated field table based on data in separate tables

It is straight forward to create a calculated field in a table that uses data IN the table... due to the fact that the expression builder is straight forward to use. However, it appears to me that the expression builder for the calculated field only works with data IN the table;
i.e: expression builder in table MYTABLE works with fields FIELD1.MYTABLE, FIELD2.MYTABLE etc.
Inventory Problem
My problem is that I have two 'count' fields that result from my queries that apply to INPUTQUERY and OUTPUTQUERY (gives me a count of all input data added and a count of all output data added) and now I want to subtract the two to get a stock.
I can't link the table that was created from my query because it wont be able to continually update do the relationship itself, and thus i'm stuck either using the expression builder/SQL.
First question:
Is it possible to have the expression builder reference data from other tables?
i.e expressionbuilder for:
MAINTABLE CALCULATEDFIELD.MAINTABLE = INPUTSUM.INPUTTABLE - OUTPUTSUM.OUTPUTTABLE
(which gives a difference of the two)?
Second question:
if the above isn't possible, can I do this through an SQL code ?
i.e
SELECT(data from INPUTSUM)
FROM(INPUTTABLE)
-
SELECT(data from OUTPUTSUM)
FROM(OUTPUTTABLE)
Try this:
SELECT SUM(T.INPUTSUM) - SUM(T.OUTPUTSUM) AS RESULTSUM
FROM
(
SELECT INPUTSUM, 0 AS OUTPUTSUM
FROM INPUTTABLE
UNION
SELECT 0 AS INPUTSUM, OUTPUTSUM
FROM OUTPUTTABLE
) AS T

Access form fields for multiple Query parameters

I am using Access 2013.
I have one table,A form and a query in database.
I am trying create query to filter data in table using form.
I have added two fields(combobox) in form.
Both are referencing different columns.
And a button to trigger.
I am using this formula in Query for 'where' clause for one field(in Query)
[Forms]![frmDataEntry]![Transaction Type] Or IsNull([Forms]![frmDataEntry]![Transaction Type])
Its working fine if I select any value, its showing data matching that value.It's showing all records when I leave it blank.
But its not working if I add same formula(changing fieldname) for other parameter too.
Its showing correct data, if I select values for both comboboxes in form.But its showing blank dataset, If I ignore any combo box.
My expectation is:
If I select both values......It should filter matching both and get result.
If I select none.............It should show all records.
If I select only one.........It should filter based on only that column.
You could use in your WHERE clause this
Like IIf(IsNull([Forms]![frmDataEntry]![Transaction Type]),"*" ,
[Forms]![frmDataEntry]![Transaction Type])

Inserting a new column into SQL

I have these queries:
SELECT *
FROM dbo.GRAUD_ProjectsByCostCategory
select right(CostCategoryId,14) as CostBreak
from dbo.GRAUD_ProjectsByCostCategory
They work well in that they give me the correct data, but I would like to know how to combine the new column CostBreak into the table of results rather than as a separate query result.
An example of the results I get are as below:
Where I want them in the same table
The data is coming from the same table so you should be able to just add that value to your initial query. You do not even have to perform a join to get it:
SELECT name,
description,
project,
CostCategoryId,
right(CostCategoryId,14) as CostBreak
FROM dbo.GRAUD_ProjectsByCostCategory