MySQL Crystal query, how do I select CurrentDate() field and blank dates? - mysql

I'm new to SQL. I'm trying to select records less than the current date which is working however we also have entries where the date field is blank which I need to include in the report. I need to be able to see both the current date AND dates that are blank. Any way to accomplish this?
{LOAN1.XLN-PROMDATE} < CurrentDate()

The correct syntax in crystal would be isnull ({datefield}) or {date field} < {?parameter} isnull is not comparable to a value - null means the absence of data, which is not comparable. Hope that helps

Related

DateDiff function in SSRS (report server) gives error?

Im trying to find the days gap between two dates using DateDiff function.
I have 2 datasets defined. If companycode is 'AB' then from one dataset else from another dataset I retrieve data.
Here is my expression. When I change to preview mode, it shows redmark to the first First(Fields!PeriodFrom.Value line. Why? (after generating report that field shows #Error
What Im doing wrong here?
=IIF(Parameters!CompanyCode.Value="AB",
DateDiff("d",First(Fields!PeriodFrom.Value, "ABReportData"), First(Fields!PeriodTo.Value, "ABReportData")),
DateDiff("d",First(Fields!PeriodFrom.Value, "XYReportData"), First(Fields!PeriodTo.Value, "XYReportData")))
I think there are two possible scenarios. First one is the expression
=First(Fields!PeriodFrom.Value, "ABReportData")
doesnt return a value. Add a column with this expression and check if you get a value.
If the value is correct, make sure that the DateDiff() function gets a date:
=IIF(Parameters!CompanyCode.Value="AB",
DateDiff("d",
CDate(First(Fields!PeriodFrom.Value, "ABReportData")),
CDate(First(Fields!PeriodTo.Value, "ABReportData"))
),
DateDiff("d",
CDate(First(Fields!PeriodFrom.Value, "XYReportData")),
CDate(First(Fields!PeriodTo.Value, "XYReportData"))
)
)

How to troubleshoot "Data type mismatch in criteria expression"

I'm creating a ms-access query to filter by month. I have my list of dates, filter by month using Month(8) as criteria in the field, and am getting a data type mismatch error. I'm not putting the number in quotation marks and I know the field I'm adding criteria to is in MM/DD/YYYY format because I'm pulling it from a query where I changed it to that format. I'm sure it's a simple fix but I am VERY new to ms-access. Thank you in advance for your help.
I'm pulling it from a query where I changed it to that format.
That is your trouble. Pull the date field as is, not as a formatted string.
Then this SQL will work:
Select * From YourQuery
Where Month([YourDateField]) = 8

Access Criteria IIF Statement Issue

I'm trying to qualify a field based on a date. If the frequency of the data is supposed to be weekly, I want to select one specific weekend date. If the frequency is monthly, I want the frequency to include the specific weekend date and all weeks thereafter. However, my statement below returns a blank table when False ("Monthly"). I'm guessing there's some specific formatting I have to do to the >= but I'm drawing a blank. Any suggestions?
=IIf([Frequency]="Weekly",[WK_end_Date],>=[WK_end_Date])
FYI... the false statement works correctly when I input only that specific criteria without the IIF statement.
Thanks,
Mark
You can't use IIf this way. Correct your Where clause like this:
Where
([Frequency] = "Weekly" And [YourDateField] = [WK_end_Date])
Or
([Frequency] <> "Weekly" And [YourDateField] >= [WK_end_Date])

Access query using calculation

I'm trying to make a query using a calculation with Date().
I have a field named [Currentordue] and a field named [duedate]. What I'm trying to accomplish is making a query to limit the results by "if [currentordue] equals "due" or if [duedate] minus today's date is less than 30 days."
I've tried a few different ways but always seem to end with either an error or with no results showing (which would be an error as well since I know there are fields that are due).
Any and all help would be appreciated.
Here is a way to use two different date conditions:
SELECT Table1.Currentordue, Table1.duedate, DateDiff("d",[duedate],Date()) AS Expr1
FROM Table1
WHERE (((DateDiff("d",[duedate],Date()))<30)) OR (((Table1.Currentordue)=[duedate]));

query to filter on specific data or no filter if blank

I have a query which filters records based on dates (start date and end date)selected in a previous form. I want the query to filter the specific date range, or output all records if the fields are left blank.
I am unfamiliar with SQL. is there a way to add an if-then statement?
I can use vba if necessary, but would like to use the Access GUI if it is possible.
If you have a parameter, used in WHERE clause (Criteria in query builder) and you want to show all records if parameter is empty, just add this parameter as new column and OR condition where indicate Is Null or, better add a column with expression Nz([MyParam],"") and in Condition area inORrow add""`. Unfortunately in query builder this construction may be quite complicated if you have few parameters, in SQL it looks much simpler, for instance in your case it will be something like this:
WHERE (MyDate >= [paramDateStart] and MyDate <= [paramDateEnd])
OR (Nz([paramDateStart],"")="" AND Nz([paramDateEnd],"") = "")
Sometimes simpler edit SQL and then switch to Design view
You can use these criteria for StartDate and EndDate respectively to compare them to themselves in case one (or both) of the search fields on the form is empty (Null):
>=Nz([Forms]![YourForm]![FromDate], [StartDate])
<=Nz([Forms]![YourForm]![ToDate], [EndDate])