SQL Select Case (2 forms, 3 values) - sql

Can the following be done, and can someone tell me some pseudo-code for my Select statement.
Form 1 contains date field RevDate
Form 2 contains date fields RevDate, CompletedDate
Form 1 can be linked to Form 2
Form 1 may not have a link to Form 2
If Form 1 has no link want to select Form1_RevDate
If Form 1 has a link, want to select
Form2_RevDate if Form2_CompletedDate is null or
Form2_CompletedDate if Form2_CompletedDate is not null

Related

DataTables yadcf Multi select filter Server Side Script

I am using DataTables with Server Side and yadcf Multi select filter.
I have a database that I need to filter by multiple Caja ID, on the Database the Caja ID is just a number (1-30) i already did the yadcf_data_14 for the label and value of the filter.
The filter works almost good when i select 1 filter. If i Select Caja ID = 1 then i shows me all the items that has 1 and also 10 to 19 and 21. I am guessing it is a contains filter not exact value.
Also, when i select the second item to filter, then I shows Nothing.
I need help on getting the filter working when i select 1 to show me exactly the value selected, and when i select 2 filters then show me all the results of the 2 selected values.
Image with 1 Filter:
Image with 2 Filter

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?

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?

Sum of a record source in access forms

I have a query that has the following display:
type $ value
1 5
1 3
1 2
2 1
2 3
This query is the record source of my form I would like the form to display the data as so
type Sum of value
1 10
2 4
is there a vba or setting way to achieve that ?
The proper way to do that is to use an aggregation function in your query, in your case it would be sum. Your query will look like this.
SELECT Type, SUM(value) As Total FROM table GROUP BY Type;
if you use the graphical query builder then you will have to follow this

variable column

I have a database in MS-Access which has field names as "1", "2", "3", ... "10".
I want to select column 1 then when I click a button, column 2, column 3, ... and so on.
How to do that?
Actually i want to make a project in JSP.
Those are impractical field names, but you can use brackets to use them in a query:
select [1] from SomeTable where SomeId = 42
A basic rule for designing databases is that data should be in the field values, not in the field names. You should consider redesigning the table so that you store the values in separate rows instead, and have a field that specifies which item is stored in the row:
select Value from SomeTable where SomeId = 42 and ValueType = 1
This will enable you to use a parameterised query instead of creating the query dynamically.
Also, this way you don't have empty fields if you use less than ten items, and the database design doesn't limit you to only ten items.
Suppose I have a table like this
id name
1 name1
2 name2
3 name3
4 name4
5 name5
Now suppose I want to choose record 1 when button 1 is clicked, second record when button 2 is clicked and so on.
So I will write a query like
select * from MyTbl where id = #btnId .
Note:- #btnId will have the value 1 for Button 1, 2 for Button 2 etc.
Or you can use case statement.
This is just an idea for accomplishing the work but as others mentioned, you should be more specific for an accurate answer.