I don´t know whats wrong with this query... I want to know how many records are on another query named: Querie_Planilla that have the following characteristics:
The date on the field PeriodoInicial has to be greater or equal to the date [FechaInicio] but a year ago
The date on the field PeriodoFinal has to be smaller to the value [FechaInicio] (Both of this conditions consider the first day of the month in FechaInicio
It has to have the same ID im looking for: PlazaID = [Vacaciones]![PlazaID]
Here is the code:
DCount("PlazaID","Querie_Planilla","PeriodoInicial >= #" & DateSerial(DatePart("yyyy",[FechaInicio])-1,
DatePart("m",[FechaInicio]),1) & "# AND PeriodoFinal < #" & DateSerial(DatePart("yyyy",[FechaInicio]),
DatePart("m",[FechaInicio]),1) & "# AND PlazaID = '" & [Vacaciones]![PlazaID] & "'")
Right now its returning 0 but at least i have 3 for each ID
Related
can you please help me to fix the following code:
The code is trying to get data according to the 2 conditions:
Select data when a checkbox and a value form a drop down list is checked
Select data when only a checkbox is checked ( this one is working fine so I am not going to list it)
If I select multiple check boxes the values are shown properly but when I try to add the second condition no values are shown.
Date looks like this DD/MM/YY
I am using vb and mysql(DB)
If c1check AndAlso ComboBox2.SelectedItem > 0 Then
searchQuery = "Select USERS_NUMBER FROM DB WHERE EXPIRATION_DATE LIKE '%" _
& String.Join("%'and EXPIRATION_DATE LIKE " + "'%", myList) _
& + "%' AND RIGHT(EXPIRATION_DATE, 3) = '%" & Trim(ComboBox2.SelectedItem.ToString) & "'"
Good Day all,
I need help with my expression. I am trying to place it in a text box in my Form. When the Product (sUPC) is selected the most recent price is automatically filled based on the current date. I have a Prices Table (Prices) that stores the current price of the product. EFFDATE is the date when the price will be applied. UPC is the ProductID on the prices table and sUPC is the combo box on my form.
DLookUp("Price","Prices","sUPC=UPC" And
Format(Now(),"dd/mm/yyyy")=DMax("[EFFDATE]","Prices",
"[EFFDATE]<=#" & Format(Now(),"dd/mm/yyyy") & "#"))
After selecting the Product the text box remains blank.
You are making it too complicated:
DLookUp("[Price]", "[Prices]", "sUPC = 'UPC' And [EFFDATE] = DMax('[EFFDATE]', '[Prices]', '[EFFDATE] <= Date()')")
For a specific date:
DLookUp("[Price]", "[Prices]", "sUPC = 'UPC' And [EFFDATE] = #" & Format(SomeOtherDateValue, "yyyy\/mm\/dd") & "#")
or a mix of these:
DLookUp("[Price]", "[Prices]", "sUPC = 'UPC' And [EFFDATE] = DMax('[EFFDATE]', '[Prices]', '[EFFDATE] <= #' & Format(SomeOtherDateValue, 'yyyy\/mm\/dd') & '#')")
DLookUp("[Price]","[Prices]","sUPC =UPC And [EFFDATE] = DMax('[EFFDATE]', '[Prices]', 'sUPC=UPC And [EFFDATE] <= #' & Format(Date(), 'dd\/mm\/yyyy') & '#')") sUPC=UPC was missing from the EFFDATE criteria –
There is a table in MS Access having 3 columns:
ID (Primary key)
Date (Date/Time)
Train no (short text)
I have designed a form where date can be selected from a combo box and according to the date selected, respective trains should be displayed.
Problem is, the query works fine on dates above 10 (like 11/1/2015) but below 10 (like 9/1/2015) it gives error : "No current record" . The record is there in the table but it doesn't display.
The query is : SELECT DISTINCT [Train No] FROM Issue WHERE [Date] = #" & dt & "#"
dt is the date selected from the combo box.
Try this:
Dim DateSelected As Date
Dim DateString As String
DateSelected = DateValue(Me!YourComboBox.Value)
DateString = Format(DateSelected, "yyyy\/mm\/dd")
SELECT DISTINCT [Train No] FROM Issue WHERE [Date] = #" & DateString & "#"
i am working on a part of my system called Patient Record Management system and in it there is an Appointment Management, and in Appointment you make a timeslot unavailable to others once occupied so here lies the problem:
there are 3 columns that are in my database: date(Date), TimeIn(Time), TimeOut(Time)
this is what i've done so far:
sqlQuery = "SELECT * FROM appointment where date = '" & datePicker.Value.ToString("dd-MM-yyyy") & "' and TimeIn <= CAST('" & timeinPicker.value.ToString("HH:mm") & "' AS Time) and TimeOut >= CAST('" & timeoutPicker.value.ToString("HH:mm") & "' AS Time)"
example if i put 12:00 to timeinPicker and 13:00 to timeoutPicker, all time between 12:00 and 13:00 should be selected, but my problem is it won't get selected, it can only select it if i input exactly 12:00 and 13:00 but when i put 12:01 and 12:59, the sql cant select it like it didnt exist
is there some way to select them so i can know which time is occupied.
P.S. i'm using MySql
if you are using java means replace & character with + and try
sqlQuery = "SELECT * FROM appointment where date = '" + datePicker.Value.ToString("dd-MM-yyyy") + "' and TimeIn <= CAST('" + timeinPicker.value.ToString("HH:mm") + "' AS Timein) and TimeOut >= CAST('" + timeoutPicker.value.ToString("HH:mm") + "' AS Timeout)";
First thing is you should use the parameterized queries always that give you protection from the Sql Injection.
You can change your query like this,
string query = "SELECT * FROM appointment where date = #DateValue and TimeIn <= CAST(#TimeInValue AS Time) and TimeOut >= CAST(#TimeOutValue AS Time)"
And then set the Paramters values to following values using the AddParamter() I don't know which programming language you are using so there will be similar method to add the parameter use that,
#DateValue = datePicker.Value.ToString("dd-MM-yyyy")
#TimeOutValue = timeoutPicker.value.ToString("HH:mm")
#TimeInValue = timeInPicker.value.ToString("HH:mm")
I have tried to select all records from a table from date1 to date2, Example Jun 28, 2014 to Jan 05, 2015, for display. Basically, sort out selected records based on date criteria. Big thanks if anyone could point out my mistake.
What I tried to do here is allowed user to select specific dates from calendar to view the records
I have gone through all answers, but still couldn't find similar solution to mine. I think, there may be some error in my syntax.
sqlDateRangeSearch = "Select * from BatteryDataTable where ((BatteryDateChanged) <= ""*" & Me.FromDTPicker.Value & "*"")" & " and ((BatteryDateChanged) <= " & """*" & Me.ToDTPicker.Value & "*""));"
Me.RecordSource = sqlDateRangeSearch
I noticed you have wildcard characters in the search criteria for the query. If using dates, you'll want to avoid those. Also, you don't need quotes for dates in access queries. If you're dynamically creating SQL I'd use something like:
sqlDateRangeSearch = "Select * from BatteryDataTable where (BatteryDateChanged <= #" & Me.FromDTPicker.Value & "#)" & " and (BatteryDateChanged <= #" & Me.ToDTPicker.Value & "#));"
Just a side note, your comparison operators are the same. I think you want it to say something like (remember the "#" symbols):
...WHERE (Field1 >= #Date1# AND Field1 < #Date2#);
Hope that helps!