EntityLoad dates in future - coldfusion

I have a table with events.
I'm trying to display a list of all the events in the future.
I'm using orm but I can't figure out for the life of me how to select dates in the future.
The filters only accept "=" and not ">".
I currently have this but it obviously doesn't work:
var events = entityLoad("tbl_events",{"eventActive" = 1, "eventDate" > NOW()},"EventDate Asc",{maxResults = count});

You have to use HQL
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSf0ed2a6d7fb07688310730d81223d0356fc-7ffe.html
var events = ormExecuteQuery(from tbl_events where eventActive = 1 AND eventDate > ?, [now()]);

Related

Check if all dates in database (sqlalchemy) are between two distinct dates

If I have created a Dates column in flask sqlalchemy and also stored some dates in it, how can I check if each and every one of these dates are between to dates that I choose
There are lots of ways to accomplish this. Here's one example.
The goal is to select all rows that have a date outside your desired range. If the result set is empty, all rows have a valid date. For good measure, we'll include any rows that don't have a date value in our "bad rows" query.
from sqlalchemy import select, or_
with Session.begin() as session:
my_start_date = '2022-01-01'
my_end_date = '2022-01-31'
query = select(MyTable).where(
or_(MyTable.date < my_start_date,
MyTable.date > my_end_date,
MyTable.date == Null)
)
results = session.execute(query).all()
Now you can take a look at the results and see what's up.
you can use between in your orm or plain query:
with Session.begin() as session:
my_start_date = '2022-01-01'
my_end_date = '2022-01-31'
q = session.query(table_name).filter(table_name.c.date.between(my_start_date,my_end_date))
.....
or
select(table_name).where(table_name.c.date.between(my_start_date, my_end_date))

Show all rows as default in calendar in Oracle Apex

I'm creating a report table type calendar where users can create back up by date select a filter that would filter out the table values depending on the user selected. (i.e. if they choose user1, then only back ups with user1 will show up)
I would like it to be when P106_BACK_UP_BY_USER = 0, the table shows all the values (aka getting rid of the "where" portion of the query.
Thank you for your help!
I'm having issues with trying to allow the user to see all the back ups of the table again (getting rid of the filtered value). My current query is this:
I would like it to be when P106_BACK_UP_BY_USER = 0, the table shows all the values (aka getting rid of the "where" portion of the query.
Thank you for your help!
You can use case when statements in your query's where condition as follows:
select *
from my_table
where my_table.created_by =
(select user_name from my_table2 where app_users_id =
case :P106_BACKUP_BY_USER when 0 then app_users_id
else :P106_BACKUP_BY_USER
end)
And for getting better help, please paste your code as text not as an image next time.
This should work too:
...
WHERE b.active_server = s.server_id
AND (:P106_BACK_UP_BY_USER = 0 OR
UPPER(b.created_by) =
(SELECT UPPER(user_name)
FROM eba_bt_app_users
WHERE app_users_id = :P106_BACK_UP_BY_USER
)
);

Power Bi Custom Filter - How to add interaction with Multiple Categories

I am creating a custom filter in power bi. My basic idea is say, I have two categories "Category and Segment" , which has following values.
Category -> Technology,Office Supplies, Furniture.
Segment -> Consumer, Corporate, Home Office.
and when user want to filter charts based on any of these values he clicks on appropriate buttons.(each value would be a button).
How to achieve this?
I have been able to do create a custom filter for one category.When I put two categories filter does not work.
Here is the result with one category -
This works exactly with three distinct values.
But when we add one more category power bi's Grouping issue comes. Meaning now the grouping is between category and segment and so nine distinct values comes. From power bi perspective its correct but what I am expecting is 6 values only , no grouping between each other.
How to overcome this?
-- Codes
-- getting data.
let viewModel: ViewModel = {
dataPoints: []
};
if (
!dv ||
!dv[0] ||
!dv[0].categorical ||
!dv[0].categorical.categories ||
!dv[0].categorical.categories[0].source
// || !dv[0].categorical.values
)
return viewModel;
let view = dv[0].categorical;
let categories = view.categories[0];
console.log("Categories:-");
console.log(categories);
// for (let j = 0; j < categories.length; j++) {
for (let i = 0, len = categories.values.length; i < len; i += 1) {
viewModel.dataPoints.push({
category: <string>categories.values[i],
identity: this.host
.createSelectionIdBuilder()
.withCategory(categories, i)
.createSelectionId()
});
}
// }
return viewModel;
-- saying to power bi to slice
__this.selectionManager.select(element.identity);
where element is each button
What I am expecting is how many ever category we put they don't group each other rather gives back distinct values of each category and for all these a button would be there. On clicking the button it filters the chart.
The approach i wsa following would not solve this issue.
so i have taken another approach meaning i would always get this multiple values only since in power bi i am specifing it to be Grouping, so what i do is get the distinct using the Set opertor in js and via the filter api i am filtering.

UPDATE with JOIN not SELECTing expected value

I'm trying to UPDATE a temporary transaction table with values from a holdings table. The fields I want to get are from the holding with the lowest date that is higher than the transaction date.
When I use below SELECT statement, the right values are shown:
SELECT h.*
FROM transaction_tmp tt
JOIN holdings h
ON tt.isin = h.isin
AND tt.portfolio = h.portfolio
WHERE h.start_date > tt.tr_date
ORDER BY h.start_date
LIMIT 1
However, when I use below UPDATE statement, incorrect values are selected/updated in transaction_tmp:
UPDATE transaction_tmp tt
JOIN holdings h
ON tt.isin = h.isin
AND tt.portfolio = h.portfolio
SET
tt.next_id = h.id,
tt.next_start_date = h.start_date
WHERE h.start_date > tt.tr_date
ORDER BY h.start_date
LIMIT 1
I'm thinking the WHERE statement is not working appropriately, but unfortunately I cannot figure out how to fix it.
Appreciate any help here!
-Joost
should work using a subquery
UPDATE transaction_tmp tt
JOIN (
SELECT h.*
FROM transaction_tmp tt
JOIN holdings h
ON tt.isin = h.isin
AND tt.portfolio = h.portfolio
WHERE h.start_date > tt.tr_date
ORDER BY h.start_date
LIMIT 1
) tx on ON tt.isin = tx.isin
AND tt.portfolio = tx.portfolio
SET
tt.next_id = tx.id,
tt.next_start_date = tx.start_date
I'm surprised your syntax works. The MySQL documentation is pretty clear that LIMIT and ORDER BY are only allowed when there is a single table reference:
UPDATE [LOW_PRIORITY] [IGNORE] table_reference
SET assignment_list
[WHERE where_condition]
[ORDER BY ...]
[LIMIT row_count]
They are not allowed for the multiple table version of UPDATE:
UPDATE [LOW_PRIORITY] [IGNORE] table_references
SET assignment_list
[WHERE where_condition]
. . .
For the multiple-table syntax, UPDATE updates rows in each table named in table_references that satisfy the conditions. Each matching row is updated once, even if it matches the conditions multiple times. For multiple-table syntax, ORDER BY and LIMIT cannot be used.
I get an error if I try such syntax.

Sorting events to show this week, month etc

I have a list of events but I'm struggling to work out how to show specific date ranges in the index view.
I would like to list the events by showing events today, this week, this month etc.
I'm new to rails so I've tried to use this site and I've come up with the following which works for today's events.
#events_today = Event.find(:all, :conditions => ["date between ? and ?", Date.today, Date.tomorrow])
But I'm not sure how to set the page to automatically update and show only this weeks events and this month.
Your basic query should do something like this:
Event.where(date: date_range)
Now before calling this query you can set the date range variable. If you only want this week:
date_range = Date.today.beginning_of_week..Date.today
Event.where(date: date_range)
Now there are all sorts of things you can do. You can select a start and end date or a custom period using either a form or a dropdown select. In this case date_range is set based on your params. You could also always use one predefined period.
If you want to work with several date range periods it could be nice to have a last_week, last_month, etc. scope in your model (or concern). Or you could simply define date_range constants in your initializers.
As per my understanding, you want to show all the event of a week or month on click of tab 'Week' or 'Month' from view.
When you clicked on month or week for getting events, you send simply month or week in params(assuming params[:events_in] hold 'week' or 'month')
apply check on this attributes of params
def get_events_in_week_or_month
if params[:events_in] =='week'
start_date_of_time_period = Date.today.beginning_of_week
end_date_of_time_period = Date.today.end_of_week
else
start_date_of_time_period = Date.today.beginning_of_month
end_date_of_time_period = Date.today.end_of_month
end
#events in descending order
#events = Event.where("date between ? and ? ", start_date_of_time_period, end_date_of_time_period).order("created_at DESC")
#events in ascending order
#events = Event.where("date between ? and ? ", start_date_of_time_period, end_date_of_time_period)
end
for getting more methods of date class, you should run following command on rails console :
Date.public_methods