How do I pass parameter as Date in vb.net web? - sql

I have a mail webform where I have to show the user only (-1) one day behind messages, so how do pass (yesterday)date as parameter and retrieve the only records of one day back ?
This query is for 'ALL' messages, but I need to filter (yesterday) one day back messages and add a hyperlink or add in a dropdown ?
select MSG_SRNO,MSG_SUBJECT,MSG_ID,MSG_CHKD,
DOF_SENT,DOF_SEEN from MESSAGES_MAILBOX where USER=1234

In sql, try
SELECT DATEADD(day,-1, GETDATE());

This should work:
DateTime yesterday = DateTime.Now.AddDays(-1);
string query = string.Format("select MSG_SRNO,MSG_SUBJECT,MSG_ID,MSG_CHKD,DOF_SENT,DOF_SEEN from MESSAGES_MAILBOX where DATEPART(year,DOF_SENT) = {0} AND DATEPART(month,DOF_SENT) = {1} AND DATEPART(day,DOF_SENT) = {2}",yesterday.Year,yesterday.Month, yesterday.Day);

Related

BigQuery GA4 querying new parameter

I have this big query GA4 dataset and on Friday I added a new parameter.
Now, I want to query the dataset including this new param but the query is returning an error because it did not exist in the past. Is there a way to make it return an empty string or something similar if the param is not found?
Excuse my poor SQL knowledge but I am unsure of what I should be searching for online to get the correct SQL syntax. This is what I have so far:
SELECT
(PARSE_DATE('%Y%m%d', event_date)) AS eventDate,
event_name,
NULLIF(params1.value.int_value, null) AS paramName
FROM
`myDataset`,
UNNEST(event_params) AS params1
WHERE
event_name = 'eventName'
AND (params1.key = 'paramName')
LIMIT 100
paramName is the new param added on Friday. When I try to run this for yesterday it works fine but when I try to run it for the entire date range, I get This query returned no results.

How to calculate Employee Service in MS Access and save in Table Fields. (not via query)

I am facing regarding the EmployeeServiceWithUs (Field in table, datatype is Number) in "years".
In TxtServiceWithUs I use the following and Result is OK:
Control Source=DateDiff("yyyy",[DateOfJoing],Date())
But in following:
Private Sub EmployeeServiceWithUs_LostFocus()
[EmployeeServiceWithUs] = [DateOfJoing] & (DateDiff("yyyy", [DateOfJoing], Date))
End Sub
I get:
error "2113 The value you enter is not valid for this field.
Is the able syntax is wrong?
DateDiff calculates the difference in calendar years, not _years of service, or age or similar. You will need a custom function like AgeSimple found here.
Then your ControlSource becomes:
=AgeSimple([DateOfJoing])
To update a (temporary) table:
Update
YourTable
Set
[EmployeeServiceWithUs] = AgeSimple([DateOfJoing])

How do I pass a parameter in Report Builder to Firebird database?

I'm looking at doing some report development for one of our Training softwares. I finally got some queries working in FB Maestro, as I'm only familiar with SQL and Oracle.
I have the following query that works and returns results, but when trying to set up a parameter for the display name, the query runs (at least it returns no errors) however the dataset does not return any data. Has anyone worked with these before?
Here's the query:
Select CertStatus, DisplayName, Count(CertStatus) From ( With cte as (Select * From (Select COURSEVERSIONSWITHAGGREGATES.CourseTitle, COURSEVERSIONSWITHAGGREGATES.CourseNumber, "MaxTrainedCompletionDate", "Course_ID", PersonnelView.DISPLAYNAME, COURSEVERSIONSWITHAGGREGATES.RecertificationValue, COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID,
CASE
WHEN COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID = 3 THEN DATEADD(year, 1*COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONVALUE, MaxTrainingView."MaxTrainedCompletionDate")
WHEN COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID = 2 THEN DATEADD(month, 1*COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONVALUE, MaxTrainingView."MaxTrainedCompletionDate")
WHEN COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID = 1 THEN DATEADD(week, 1*COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONVALUE, MaxTrainingView."MaxTrainedCompletionDate")
WHEN COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID = 0 THEN DATEADD(day, 1*COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONVALUE, MaxTrainingView."MaxTrainedCompletionDate") END
AS ExpirationDate
From MAXTRAININGVIEW
INNER JOIN PERSONNELVIEW ON (MAXTRAININGVIEW."Personnel_ID" = PERSONNELVIEW.PERSONNELID) INNER JOIN COURSEVERSIONSWITHAGGREGATES ON (MAXTRAININGVIEW."Course_ID" = COURSEVERSIONSWITHAGGREGATES.COURSEID)
WHERE Personnelview.DisplayName = 'Aaron')) Select CourseTitle, CourseNumber, "MaxTrainedCompletionDate", "Course_ID", DisplayName, RecertificationValue, Recertificationunit_ID, ExpirationDate,
CASE WHEN ExpirationDate > current_date Then 'Active' WHEN ExpirationDate < current_date Then 'Expired' END As CertStatus from cte) Group By CertStatus, DisplayName
This returns values with the static value of 'Aaron' in report builder. But trying to use a parameter, it does not throw an error in report builder, however it just does not return any data.
For example this:
WHERE Personnelview.DisplayName = '#DisplayName'))
I've got the parameter based off another data set query, and that seems to work (it gives me the option to select employees)
Here is an example of it passing 'Aaron' (with personal info removed)
Example of passing #FName Parameter:
If you want to pass the parameter in report, other type database might not recognize query like "where [field] in #parameter", so I think you could try to use filter to achieve this goal(create a filter in dataset, and create a parameter, then specify it in filter properties).

Date comparison on Kayako Query Language - KQL

I am using Kayako Querying Language and trying to get the query to return all closed/resolved, closed/unresolved, and review tickets from a specified month. When I run the query, every ticket ever comes up, and it seems to ignore the date function I am using. What am I doing wrong?
SELECT COUNT(*) AS Total
FROM ‘Tickets'
WHERE ‘Tickets.Creation Date’ = month(June 2016) AND ‘Tickets.Status’ = ‘Closed’ OR ‘Tickets.Status’ = ‘Resolved’ OR ‘Tickets.Status’ = ‘Unresolved'
GROUP BY ‘Tickets.Status'
Thanks.
Replace the date comparison in your WHERE clause for this:
WHERE 'Tickets.Creation Date':Month = 6 and 'Tickets.Creation Date':Year = 2016
Be also careful with the quotes, you sometimes use ‘ and others '

Storing Select Query result in Variable Ruby on Rails

I wanted to know how we could store the result of my select query on a variable.
#ppt2 = Ppt.select('slide_name').where('id=?',4)
#ppt1 = Ppt.update_all({:time2=>#ppt2},['id like ?','1'])
Here, slide_name and time2 are both text attributes of the same table ppt.
What happens on the above execution is that the time2 field in id=1 gets the value "#ppt2" whereas I want it to get the value of slide_name from id=4 which does not get stored in #ppt1.
In other words, how do I store the value of the select query in #ppt2 so that it can be used in the next line?
Any help is appreciated.
Call the slide_name method on your first result.
#ppt2 = Ppt.select('slide_name').find(4).slide_name