I've been searching the web and asked around, but can't seem to find an answer to my problem...
I have a running ODBC connection with my FrontBase database in OpenOffice Base. I manage to select everything I want, but when I only want to show the records between certain dates, or even one date I keep on getting a Semantic Error.
Here's my query:
SELECT * FROM "SALES" WHERE "DATE" = '2014-04-01'
Just in case you suggest using # for the date, it doesn't work either
DATE '2014-04-01' is also unsuccessful :(
Anyone have any ideas?
After a lot of trial and errors I took a closer look at the OpenOfficeBase interface. I was sure nothing was wrong with my statement so there must be something in Base that I'm missing.
In the toolbar there's a button with SQL and a checkmark which says "Execute SQL-command immediatly". Thought it wouldn't do any harm if I enabled it and gave it a try. And there it was, my query with date filter! I have no idea why that button is there or what it's exact function is, but enabling it made my query work.
Thanks anyway for the suggestions, but apparently we've got to look further than just the language ;-)
A shot in the dark here. Youŕe using a FrontBase database, googling on "Frontbase select date range" gave me this page: http://www.frontbase.com/documentation/LookSeeIntro-2.3.html
There they have this example query:
SELECT
receiver FROM memo_mails
WHERE
sender = 'QA' AND
CAST(dateSent AS DATE) < DATE '2001-06-01' AND
SATISFIES(quickx, 'Periscope & invoice');
So based on that example, I would try
SELECT
* FROM "Sales"
WHERE
(CAST("Sales"."SalesDate" AS DATE) >= DATE '2014-06-01') AND
(CAST("Sales"."SalesDate" AS DATE) <= DATE '2014-06-30');
SELECT * FROM SALES WHERE DATE = '2014-04-01'
The above should work as long as there is no time in the column you are trying to select from. Whats the columns data type?
If you're still looking for answers
SELECT * FROM "SALES" WHERE "DATE" = {D '2014-04-01'} It seems that one should put the letter D to signify that it is a date and not a string/varchar. I hope this helps, even though the question is 1 year old.
Related
I'm working on a query that pulls a date from another query, I have my reasons for the nesting. The problem I'm facing is that there is a field that is called DueDate.
My SQL is
SELECT DueDate
FROM qryDueDates
WHERE DueDates <= DateAdd("d",60,Date())
The data causing the issue is when it equals something like "1/25/2019", "11/19/2019" or any date in 2019.
Goal
I need to limit the results to show dates that are expired or expiring within 60 days or less.
I'm trying to prepare the dataset for the conditional formatting.
if you can put your nested sub-query in your post that may give better picture, and if you can mention what is the error you are getting that may also help. Since you mentioned that you are getting error only when sub-query returns certain dates, I would suggest that cast your sub-query result to DATE if you have not already done.
Below is my attempt to help you with limited information I could extract from your post. I have used some of MS-SQL function below, please replace with your DB specific function.
SELECT myDates.* FROM (select COLUMN_NAME DueDates from TABLE_NAME) as myDates WHERE myDates.DueDates <= DateAdd("d",60, GETDATE())
Turns out that the original query was screwing it up. I moved the query into the main one and it worked.
A colleague wrote a view that needs changing; the problem is I was not there when it was made, so I do not know it inside out as if I coded this SQL view.
My colleague created a view and used CTEs to grab data faster. This is the CTE I'm having trouble with
vDateRange AS
(
SELECT
Date,
Year,
Month,
Day,
DayOfWeek
FROM
Util.fnDateRange('2017-08-17', '2017-08-22')
)
so as you can see this view will only get data from that date range, can someone show me how I can grab FROM something else instead of the Util.fnDateRange() because this CTE is used so many times in the view I can't just comment it out.
I changed the query by using the range like this instead:
Util.fnDateRange('01-01-2014', GETUTCDATE())
now i can get from 2014 till the date of today.
I have a list of items I'd like to view by the date they most recently occurred. I am currently using this query.
SELECT Cleaning1, Max(Date1) AS most_recent
FROM CleaningLog
GROUP BY Cleaning1;
It worked yesterday when I was at work, but suddenly stopped working. It won't show to most recent date an event occurred for some of the items. I was wondering why this would suddenly stop working. I added date parameters to the four queries I have with this code. When that stopped working correctly, I decided to create a test query, without date parameters, and it still won't show me the most recent event that I typed in.
I tried playing around with the <, >, = signs in the date portion of the code, but nothing seems to capture the dates I added this morning. I should mention this is what I have for codes that have a date parameter:
SELECT Cleaning1, Max(Date1) AS most_recent
FROM CleaningLog
GROUP BY Cleaning1
HAVING Max(Date1) < Now() - 30;
What do you think would be a potential cause for this query to stop capturing dates? The dates in my database are not in chronological order, because I had to manually type in events that occurred in the past. Any help would be appreciated!
It seems like it won't use the data after ID 89. It worked fine yesterday afternoon. I added from ID 59 on this morning. All of the data was added the same way, through a form:
Convert your text date to a true date:
SELECT
Cleaning1,
Max(CDate(Date1)) AS most_recent
FROM
CleaningLog
GROUP BY
Cleaning1
HAVING
Max(CDate(Date1)) < Date() - 30;
I'm wondering if it it possible to SELECT records in which [RRRmonth] field is the current month? I've written this SQL in many ways and can't seen to get it to work.
SELECT CFRRR.CFRRRID, CFRRR.[program], CFRRR.[language]
FROM CFRRR
WHERE (((CFRRR.[workername]) Is Null) AND ((CFRRR.RRRmonth)=Month([RRRmonth])));
Thanks!
The month function will give you the month of a date/time field. The date function will give you the current date. Use the two together will give you the answer you're looking for
SELECT CFRRR.CFRRRID, CFRRR.[program], CFRRR.[language]
FROM CFRRR
WHERE CFRRR.[workername] Is Null AND month(CFRRR.[RRRmonth])=month(Date());
You also don't need all those parenthesis and makes for a messy query.
I've had a sudden failure in one of my reporting routines and have traced it back to the having portion of my statement. The function this has been serving, up until 2 days ago, was selecting the most recent date from the dbo.data_feed_file table (column name: File_Date).
Statement follows
HAVING (dbo.data_feed_file.file_date = (Select MAX(File_Date) as Expr1
FROM dbo.data_feed_file AS data_feed_file_1))
First: is there an alternative way to write this? I've gotten my report working by removing the statement, it's just 2.5 million more lines than I want. I know I can hard code the date to pull just the specific date I want, but automation is obviously preferred.
Second: Does anyone know what could cause this to spontaneously fail? I'm the only person with access to edit this query so I know nothing was changed (no really, nothing changed).
Thanks in advance.
Edit: To add clarification: There is no error message, the column headers are showing up as anticipated but no data is populated, it's just blank fields (as though nothing met the having criteria). The statement completes as though there is nothing wrong. I've confirmed there are no NULL values in the File_Date column.
I can think of two reasons why no rows would return. The first is that the subquery is returning NULL. This is easily fixed as:
HAVING (dbo.data_feed_file.file_date = (Select MAX(File_Date) as Expr1
FROM dbo.data_feed_file AS data_feed_file_1
where file_date is not null))
The second is that File_Date is stored as a datetime, rather than a date. If so, you might have a where clause that filters out the most recent value, and be missing it in the having clause. If you intend dates, but the value is stored as a datetime, then you can try:
HAVING (cast(dbo.data_feed_file.file_date as date) =
(Select cast(MAX(File_Date) as date) as Expr1
FROM dbo.data_feed_file AS data_feed_file_1
where file_date is not null))