seeking syntax for date in where clause in Jet OLEDB - ruby

I have a problem of using the where clause for limiting dates
I can't even get a simple statement like on "Feb 5 2010" to work,
e.g.,
select * from LineItems where DueDate = 2/5/2010;
I tried
"2/5/2010"
"2010/2/5"
"2010-2-5"
"2010-02-05"
2010-2-5
2010-02-05
...
but none worked.
Does anyone have an idea what the proper format for the date should
be? And should it be quoted?
Thank You!

This works for me in a Query
SELECT *
FROM Table1
where mydate = 2010/2/5
Writing a date like that is unambiguous; the other way round will depend on your locale settings.

Hey Guys, I did figured out that you must surround the date with a pair of #'s. Just leaving the date unsurrounded does not work for me. I figured this out by saving a "Filter" in the Data View of Access as query, then I looked at that query in SQL view.

Related

How to use WHERE statement in ni-fi QueryRecord processor?

So I have this dummy csv file:
year, value
2001,А
2001,B
2002,A
2021,B
2022,A
2022,B
I've ingested it using GetFile processor and now I am trying to create few files out of this one
according to a value of "year" column.
So I am using QueryRecord processor and I've created a couple of attributes in this processor such as:
year_2001: select * from flowfile where year = 2001 (also I've tried year = '2001')
year_2022: select * from flowfile where year = 2022
But when I start this processor I am getting some huge error I don't understand. It is too huge to copy here but basically it says that my SQL statement ain't valid. When I remove "where" clause it works fine, so apparently it is the "where" clause that I don't seem to get right.
Thank you beforehand.
UPD. I've found this article and it seems like I do exactly same as example shows.
Ok, I have figure this out. Apparently naming my column "year" wasn't such a good idea. Seems like it conflicted with year function or something. So I just enclosed year in quotes and it worked.
So the correct sql statement will be
select * from flowfile where "year" = '2001'

Browsing the year in a string

So I have a field containing dates; however not all years are the same. How do I browse for a specific year. I have tried the following, but it doesn't really work.
BROWSE FIELDS Lastcall FOR Lastcall LIKE '%2019%'
thanks in advance
OR.. exactly as you had it which will allow you to directly edit the records too. IF the "LastCall" is a date based field
BROWSE FIELDS Lastcall FOR year( Lastcall ) = 2019
if it is a string field, you could do
BROWSE FIELDS Lastcall FOR '2019' $ Lastcall
The "$" means does the string on the left exist anywhere in the field on the right (which you could concatenate multiple string fields if you so wanted to.
There's a number of ways you could do this.
Set a filter on the table:
SET FILTER TO YEAR(LastCall) = 2019
Use a select query:
SELECT * FROM TableName WHERE YEAR(LastCall) = 2019
If your table is really large I would suggest using the select statement.

OBIEE: Casting String to date then date to string

FILTER("source"."recordCount" USING "source"."snapshot_date" =
EVALUATE('TO_CHAR(%1, ''YYYYMMDD'')', TIMESTAMPADD(SQL_TSI_DAY, -7, EVALUATE('TO_DATE(%1, %2)', "source"."snapshot_date" , 'YYYYMMDD'))))
So i have this piece of code here. I know some will say "Just use the AGO function" But somehow it's causing problems because of it's connection with other tables so what I'm trying to achieve here is like a remake. The process goes this way:
The snapshot_date there is actually in varchar format and not date. So it's like "20131016" and I'm trying to change it to a date then subtract 7 days from it using the TIMESTAMPADD function and then finally returning it back to varchar to use it with FILTER.
This snippet somehow works when testing the FILTER using hardcoded values like "20131016" for example but when tested out with the code above all the row are blank. On paper, the process i assumed would happen goes lke this. "20131016" turns to a date with a format of 20131016 (yyyymmdd) and then less 7 days: 20131009 and then turned into char again "20131009" to be used in the filter.
But somehow that doesn't happen. I think the data format is not applying either to the string->date or the date->string conversion. which results to the values not getting a match at all.
Anyone have any idea what's wrong with my code?
By the way I've already tried to use CAST instead of EVALUATE or TO_TIMEDATE with the same result. Oh and this goes to the formula of the column in BMM.
Thanks
You might get some clues by looking at the SQL generated by the BI Server. I can't see any issues with your column expression, so I wouldn't limit your debugging to that alone.
A query returning nulls is often caused by incorrect levels being set (especially on logical table sources, but potentially on a measure column too). This will often result in some form of SELECT NULL FROM ... in the physical SQL.
Try this :
FILTER("source"."recordCount" USING "source"."snapshot_date" =
EVALUATE('TO_CHAR(%1, %2)', TIMESTAMPADD(SQL_TSI_DAY, -7, EVALUATE('TO_DATE(%1, %2)', TO_CHAR("source"."snapshot_date" , 'YYYYMMDD') , 'YYYYMMDD')) , 'YYYYMMDD'))

How can I format a date in the Select property of an EntityDataSource

Fairly straight forward... I have an EntityDataSource where, in the Select property I'm pulling a variety of fields. One of which is a Date that I would like to have returned in the "MM/dd/yyyy" format. How can I accomplish this?
You could use the .ToString(Format Here)
DateTime time = EDS.Field;
Console.WriteLine(time.ToString(MM/dd/yyyy));
This solution works fine with me:
cast(it.[interview_start_date] as System.String)

Oracle 10g Database Date Conversion to 'yyyy-iw' problems?

I'm not sure if this is a question or more of an exploration of a possible bug or a question about a better way to do handle this.
I have a rollup report that uses the
select column1id, column2date
from table1
where to_char(column2date,'yyyy-iw') = to_char(to_date('2012-12-31','yyyy-mm-dd'),'yyyy-iw')
The line: to_char(to_date('2012-12-31','yyyy-mm-dd'),'yyyy-iw') is converting to 2012-01, wrapping back to the beginning of the year.
Digging a bit further I find that the date 2012-12-31 is neither included in week: 2012-52 nor is it included in 2013-01, and 2012-53 doesn't return any data either... so I'm at a loss of what's going on here.
https://forums.oracle.com/forums/thread.jspa?threadID=995899
Ravi Kumar wrote: you need to use IYYY in format.
BluShadow wrote: ... When it calculates the YYYY and IW these are independant of each other so it won't reduce the YYYY output to [2013] just because you have included IW in the format mask. It looks at components of the mask and not the whole thing in combination.
select to_char(to_date('2012-12-31','yyyy-mm-dd'),'iyyy-iw') from dual;
returns 2013-01.
I think your WHERE clause should be:
where to_char(column2date,'iyyy-iw') = to_char(to_date('2012-12-31','yyyy-mm-dd'),'iyyy-iw')

Resources