Retrieving a required row and column - sql

I want to create a windows form in which I have a combo box as I select an item from the combo box I want to display the values of the row ..
Example I have a table like this:
Name Roll no
-----------------
R. 1
A. 2
B. 7
Now as I select a A from the combo box I want to display 2 on a label of a Winform ..

Related

Access filters on splitform through query to report

I have a splitform and what I want to do is open report on filter I use in this spltiform. What's important is that in this splitform you can do the correction of the row (you can't edit the previous row, but it creates two additional rows - one is negative and the other is to edit and I have one column which stores the ID of corrected row - CorrectedRowID). So I can't create report based on that table, so I created a query which groups this data by CorrectedRowID and it takes the last row of each ID so I have only the newest row of every ID. Then based on that query I created report.
On the splitform I have button which opens the report. But what I want is that when I have filter in this splitform and I click on the button Open Form it opens the report already on the filters. I have used this code in this button in VBA:
Private Sub Command282_Click()
DoCmd.OpenReport "tb_ewid_WNT1_raport", acViewPreview, , Me.filter
End Sub
When I create a normal report (not based on query) filter works great, but when I put some filter on the data in this splitform on one column it asks me for the value of the column on which I want to filter my data.
The query returns the newest rows of each ID. For example:
ID
Name
Quantity
Price
CorrectedRowID
IsCorrection
1
bread
4
1,5
1
No
2
milk
3
2,3
2
No
3
bread
-4
1,5
1
Yes
4
bread
11
1,5
1
Yes
In this case query will return this, so for each CorrectedRowID it returns the highest ID:
ID
Name
Quantity
Price
CorrectedRowID
IsCorrection
2
milk
3
2,3
2
No
4
bread
11
1,5
1
Yes
I created the report based on this query. And I also created a button on splitform which uses the code I wrote up. When I filter my data and when I click on this button it asks me for the value for some column (it's not the same every time). The values that it asks for are combo boxes which take the values from not the same table. The query uses JOIN.
Where did I make mistake?

Choosing which rows to sum and average in either SSRS or SQL

ROW column 1 column 2
1 A 1
2 A 1
3 A 3
4 A 1
5 A 2
6 B 1
7 B 3
8 B 1
Pic of table
Lets say I have this table as shown above. I want to be able to average SELECTED values from column 2. Am I able to use any function in SSRS that allows me to select which value to use to average? The end goal is to allow the user to interactively choose which value to average.
For example if I would want to use ("Row 1 + Row 2 + Row 4")/3, or (Row 6 + Row 8)/2, how can I go about letting the end user to choose those values to average?
Is there something that I need to do in SQL first to make it easier in SSRS?
The idea is by using report parameter and dataset filter
Add parameter in SSRS to allow user input of multiple values, set the available values for row-1, row-2, and so on
here for your reference how to add the parameter in SSRS
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/add-change-or-delete-a-report-parameter-report-builder-and-ssrs?view=sql-server-ver15#:~:text=To%20add%20or%20edit%20a,or%20accept%20the%20default%20name.
after you add the parameter, let's say you already have a dataset which is SQL query such as:
SELECT *
FROM the_table
Right click on your dataset, on properties, in the filter tab, add a filter for the column ROW IN parameter that you have made earlier
after you add filter on your dataset, on your report, simply use that dataset and put expression AVG(Column 2)

remove duplicate values from record by removing dropdown value after selection

I have one dropdown in my form .....
if we click dropdown and it shows vales like 1
2
3
4 etc
I select value (1) in dropdown and saved those values in table successfully.
i need to remove the selected value**(1)** from dropdown after saved those values in table ....
If we click the dropdown again....I need the below result.....
I need result like 2
3
4
value 1 have to remove from the dropdown...How?

Split Data into two table on Crystal Report + VB NET

I am developing an application that display Data from database to CReport. I am using VB NET and Crystal Reports to do this. The report comes out fine when only print one table same as data table from query database. e.g
Group Name Amount
A Test1 10
A Test2 11
A Test3 10
B Test4 11
B Test5 12
actually data quite a long up to three pages of report and more than 3 field,9 field exactly,and now i wanna display data report split on two table horizontaly based on group field,the left table group A and the other on the right table group B, on the same page of report. e.g
Group Name Amount Group Name Amount
A Test1 10 B Test4 11
A Test2 11 B Test5 12
A Test3 11
Can someone please tell me how to accomplish this ???
you just need to copy the same data field to the other side of the report. Left click the data field, select suppress and start entering the formula:
YourFieldName = 'A'
for the right horizontal
and
YourFieldName = 'B'
for the left horizontal.
Then the section should be formatted according to what you needed, by displaying A only at the left side and B only at the right side
Put those field in the detail section first before applying the formula.

MS Access Form: Use value of first Combobox to filter options of second Combobox?

As an example, let's use food.
Table: Food
ID || Type || Name
1 || Fruit || Apple
2 || Fruit || Orange
3 || Veggie || Pea
4 || Veggie || Corn
Combobox 1: TypeCB
Row Source (SQL):
SELECT DISTINCT
Count([Food].ID) AS CountOfID,
[Food].Type
FROM [Food]
ORDER BY [Food].Type;
(The reason I use "CountofID" is the get the unique Type values, otherwise they're repeated since the ID's are unique)
Now this works perfectly for the first, however, when I try to pull the value over to my next ComboBox, it the second combobox remains empty. Refreshing the Form with the first combobox filled doesn't fix it.
Combobox 2: NameCB
Row Source (SQL):
SELECT
Count([Food].ID) AS CountOfID,
[Food].Name
FROM [Food]
HAVING ((([Food].Type)=[Forms]![Food Form]![TypeCB].[SelText]));
Is there another/a better way to grab this data?
You don't need Count in the Row Source of your TypeCB because you're only using the Type column. If you leave it in, be sure the Bound Column property of TypeCB is set to 2 so the value of the combo box will pick up from the Type column rather than CountOfID.
Your NameCB Row Source is OK, except for the [SelText] property. Change it:
SELECT
Count([Food].ID) AS CountOfID,
[Food].Name
FROM [Food]
HAVING ((([Food].Type)=[Forms]![Food Form]![TypeCB]));
If the Bound Column property of your TypeCB combo box is set to the column with the Type value, you can reference the control itself to get the value.
In the After Update event of the TypeCB combo box, add NameCB.Requery() to refresh the NameCB combo box.