How to create conditional dropdown list using Microsoft access db? - database

I need your help in this please.
I want to have a conditional dropdown list in access database, this is an example;
Table1
Column1 | Column2 | Column3
1 | dropdown list with two option “ fruit or vegetable”
If user select fruit I want to see all fruits option in column3 as a dropdown list also. And verses varsa.
How can i do this?
I’m waiting for your answers! :)

Related

Update multiple columns with the selected value from multi select dropdown in MVC

I have a multi dropdown list in mvc, I need to save the selected value in the same table but a different column in sql server
1.Fruits
-Fruits A
*Fruits B
table A
-------------------------
Fruits | Fruits 1
-------------------------
Fruits A | Fruits B
You can pass the selected values as comma separated like (Fruits1,Fruits2 etc). Then in SQL you can split up the Comma separated string as per your table columns.
Latest version SQL support the split functionality as default.

Access database help - picking football games

I am trying to create a database for picking football game winners.
Simply, I have a table of available games:
| GameID | AwayTeamName | HomeTeamName |
1 Team1 Team2
2 Team3 Team4
etc.
And
Table2
| GameID | MyPick |
1 drop-down here
2 drop-down here
etc.
I'm trying to have MyPick be a drop-down showing only the AwayTeamName and HomeTeamName for GameID for me to pick from.
I've tried using the lookup wizard to no avail as well as using a query.
I'm using Access 2019.
Any suggestions? Thank you in advance.
UPDATE:
I have created this SQL query:
SELECT [Raw Data].[AWAY TEAM] AS [SELECTION]
FROM [Raw Data]
WHERE [Raw Data].[Game ID] = 20191901
UNION ALL
SELECT [Raw Data].[HOME TEAM]
FROM [Raw Data]
WHERE [Raw Data].[Game ID] = 20191901
and it works perfectly. Now I just need to figure out how to send/tell the query to use the Game ID I'm currently working on.
CLARIFICATION:
I am using a form for data input. I already have the list of games loaded. I just need to be able to select from the two teams listed on the form.
The form is something like this:
Game ID
AwayTeam
Home Team
Pick the winner: _______________
First Prev Next Last
I'm wanting to just have the two teams listed in the combobox for picking.

Sql server 2014 counted columns into another table

hello everyone I am new to programming and I would like some help on this issue I am facing.
I have two tables clients and box.
clients (id,name....boxnum)
box(id,totalbox,usedbox,availablebox)
what I am trying to do is get the available box in the box table according to a rule that (availablebox=total-used) where used is counted in the clients table
example:
----------
client box
----------
a 1
----------
b 2
----------
c 1
----------
what I need is to count each time the box num repeated in clients table and get the value of it to use it in the box table as usedbox.
Use Count Aggregate and Group By clause
Select Box,count(*) as Box_Count
From Yourtable
Group by Box
If you want to insert the count result into another table then use Insert into..select syntax
Insert into Target_table(Box,Box_Count)
Select Box,count(*) as Box_Count
From Yourtable
Group by Box

Pivottable on SSAS cube: hide rows without result on measure

I'm having trouble hiding rows that have no data for certain dimension members for the selected measure, however there are rows for that member in the measuregroup.
Consider the following datasource for the measuregroup:
+---------+----------+----------+----------+--------+
| invoice | customer | subtotal | shipping | total |
+---------+----------+----------+----------+--------+
| 1 | a | 12.95 | 2.50 | 15.45 |
| 2 | a | 7.50 | | 7.50 |
| 3 | b | 125.00 | | 125.00 |
+---------+----------+----------+----------+--------+
When trying to create a pivottable based on a measuregroup in a SSAS-cube, this might result in the following:
However, I would like to hide the row for Customer b, since there are no results in the given pivottable. I have tried using Pivottable Options -> Display -> Show items with no data on rows but that only works for showing/hiding a Customer that's not at all referenced in the given measuregroup, say Customer c.
Is there any way to hide rows without results for the given measure, without creating a seperate measuregroup WHERE shipping IS NOT NULL?
I'm using SQL-server 2008 and Excel 2013
Edit:
For clarification, I'm using Excel to connect to the SSAS cube. The resulting pivottable (in Excel) looks like the given image.
In the DSV find the table with the shipping column and add a calculated column with expression:
Case when shipping <> 0 then shipping end
Please go to the properties window for the Shipping measure in the cube designer in BIDS and change the NullHandling property to Preserve. Change the source column to the new calculated column. Then redeploy and I am hopeful that row in your pivot will disappear.
And ensure Pivottable Options -> Display -> Show items with no data on rows is unchecked.
If that still doesn't do it connect the Object Explorer window of Management Studio to SSAS and tell us what version number it shows in the server node. Could be you aren't on the latest service pack and this is a bug.
Go in your pivot table in Excel, click on the dropdown on your customer column. In the dropdown menu you will find an option called Value Filters. There you can set something like Shipping greater than 0.1.
This filters your Customer dimension column based on the measure values.
Maybe something like this (but I don't see the pivot...)
DECLARE #tbl TABLE(invoice INT,customer VARCHAR(10),subtotal DECIMAL(8,2),shipping DECIMAL(8,2),total DECIMAL(8,2));
INSERT INTO #tbl VALUES
(1,'a',12.95,2.50,15.45)
,(2,'a',7.50,NULL,7.50)
,(3,'b',125.00,NULL,125.00);
SELECT customer, SUM(shipping) AS SumShipping
FROM #tbl
GROUP BY customer
HAVING SUM(shipping) IS NOT NULL

Preventing SQL injection in a report generator with custom formulas

For my customers, I am building a custom report generator, so they can create their own reports.
The concept is this: In a control table, they fill in the content of report columns. Each column can either consist of data from DIFFERENT DATA SOURCES (=tables), or of a FORMULA.
Here is a reduced sample how this looks:
Column | Source | Year | Account | Formula
----------------------------------------------
col1 | TAB1 | 2015 | SALES | (null)
col2 | TAB2 | 2014 | SALES | (null)
col3 | FORMULA | (null) | (null) | ([col2]-[col1])
So col1 and col2 get data from tables tab1 and tab2, and col3 calculates the difference.
A stored procedure then creates a dynamic SQL, and delivers the report data.
The resulting SQL query looks like this:
SELECT
(SELECT sum(val) from tab1 where Year=2015 and Account='SALES') as col1,
(SELECT sum(val) from tab2 where Year=2014 and Account='SALES') as col2,
(
(SELECT sum(val) from tab1 where Year=2015 and Account='SALES')
-
(SELECT sum(val) from tab2 where Year=2014 and Account='SALES')
) as col3 ;
In reality it is far more complex, because there are more parameters, and I'm using coalesce(), etc.
My main headache are the formulas. While they give users a very flexible tool at hand, it is total vulnerable for SQL injections.
Just wanted to know if there is some simple way to check a parameter for a possible SQL injection.
Otherwise I think that I need to limit the flexibility of the system for normal users, and only "super users" get access to the full flexible reports.
not really - many injections involve comments (to comment out the rest of the regulare statment) so you could check for comments (-- and /*) and the ; sign (end of statment).
On the other side if you allow your users to put anything into the filters - why should not someone write a filter as 1 = (select password from users where username = 'admin') to provoke an error message Error converting 'ReallyStrongPassword' to integer'?
Furthermore I guess that performance will be a much bigger problem as injection if I see your queries (it will read tab1 and tab2 twice instead only once if you would write it 'regular').
Edit:
You could check for SQL codewords as select, update, delete, exec ... in the filter parameter, to harden your code / queries.

Resources