using :APP_USER in a query in apex application - oracle

I have a query in my apex page and I want to see the result of this query in the page:
select locs.LOCATION_DESCRIPTION "LOCATION", rsrv.Room_ID "Room Number",
rsrv.WORKPLACE_ID "Desk Number", rsrv.RESERVATION_DATE "Date", rsrv.TIME_FROM
"From", rsrv.TIME_TO "To"
FROM WPB_RESERVATIONS rsrv, WPB_USERNAMES usrs, WPB_LOCATIONS locs
WHERE upper(usrs.APEX_USERNAME) = upper(:APP_USER)
AND (upper(rsrv.FIRST_NAME) = upper(usrs.FIRST_NAME) AND upper(rsrv.LAST_NAME) =
upper(usrs.LAST_NAME))
AND rsrv.LOC_ID = locs.LOC_ID
AND rsrv.RESERVATION_DATE >= SYSDATE-1
but it shows nothing. IT seems this part doesnt work:
WHERE upper(usrs.APEX_USERNAME) = upper(:APP_USER)
because when I change it to this I can see the results that I want:
WHERE upper(usrs.APEX_USERNAME) = 'MS'
I've read all topics about using :APP_USER or v(APP_USER) and tried different solutions, but non of them works.

Well, if it works when you hardcode 'MS' and it does not work when you do UPPER(:APP_USER) that indicates that those 2 values are not the same. You have not mentioned what the value for the APP_USER is. Best way to check is to open the session state window from the developer toolbar and check what the value for "User" is.

If you're still working on this, my suggestion would be to temporarily:
Hardcode the 'MS' into the WHERE clause (or drop that comparison entirely,
Add a dummy column to your query with this as the source
upper(:APP_USER) AS the_app_user
That will let you see the application item value in the report results.

Related

how to add a where clause to a query in Power query?

I need to return a set of data from a database based on a parameter that is in excel.
So I have created the following 'Query1'
let
Source = Sql.Database("VI107064\SQLEXPRESS", "Stock", [Query="select * from customer#(lf)where custID = " &CustID])
in
Source
Then I created the 'CustID'
let
Source = Excel.CurrentWorkbook(){[Name="CustID"]}[Content],
SourceValue = Record.Field(Source{0}, "CustID"),
SourceText = Number.ToText(SourceValue)
in
SourceText
The issue is that Excel is complaining that the query refernces other queries or steps, so it may not directly access a datasource Please rebuild this data combination.
So after reading https://www.excelguru.ca/blog/2015/03/11/power-query-errors-please-rebuild-this-data-combination/
I understood the issue, and I think for me to fix the problem, I need to duplicate query1 to query2.
Update query 1 so that it just returns the table.
Update query 2 so that it takes query 1 as a source and then adds the filter.
Is that correct? or is there a better way to do this?
The simplest solution, if you aren't worried about data privacy settings, is to turn those settings off.
File > Options and settings > Query Options > Privacy
In any case, I'd recommend cleaning up the code to be a single query that looks something like this:
let
CustID = Excel.CurrentWorkbook(){[Name="CustID"]}[Content]{0}[Column1],
Source = Sql.Database("VI107064\SQLEXPRESS", "Stock"){[Schema="dbo",Item="customer"]}[Data],
#"Filtered Rows" = Table.SelectRows(Source, each ([CustID] = CustID))
in
#"Filtered Rows"
If you right-click on the last step in the Applied Steps pane, you can see that this get interpreted in the SQL Native Query as
select [_].[ <A bunch of columns here> ],
[_].[ <...> ],
[_].[ <etc> ]
from [dbo].[customer] as [_]
where [_].[CustID] = <CustID value here>

For table cmdb_rel_ci, I want to retrieve unique parent.sys_class_name with count for "type=In Rack::Rack contains"

For table cmdb_rel_ci, I want to retrieve unique parent.sys_class_name with count for "type=In Rack::Rack contains". I am doing practice in out of the box instance.
At table level URL is as below:
URL
I want to retrieve result from above URL with my below script.
var count = new GlideAggregate('cmdb_rel_ci');
count.addQuery('type','e76b8c7b0a0a0aa70082c9f7c2f9dc64');// sys_id of type In Rack::Rack contains e76b8c7b0a0a0aa70082c9f7c2f9dc64
count.addAggregate('COUNT', 'parent.sys_class_name');
count.query();
while(count.next()){
var parentClassName = count.parent.sys_class_name.toString();
var parentClassNameCount = count.getAggregate('COUNT','parent.sys_class_name');
gs.log(parentClassName + " : " + parentClassNameCount );
}
The issue is I am getting parentClassName empty.
Try this instead:
var parentClassName = count.getValue("parent.sys_class_name")
Since it's a GlideAggregate query (instead of GlideRecord), the query being issued isn't returning all of the fields on the target table. With GlideRecord, dot-walking through a reference field (e.g. parent.sys_class_name) automatically resolves that referenced record to provide access to its field values. This is made possible by the fact that the driving/original query brought back the value of the parent field. This is not happening with GlideAggregate. The query in this case basically looks like:
SELECT cmdb1.`sys_class_name` AS `parent_sys_class_name`, count(*)
FROM (cmdb_rel_ci cmdb_rel_ci0 LEFT JOIN cmdb cmdb1 ON cmdb_rel_ci0.`parent` = cmdb1.`sys_id` )
WHERE cmdb_rel_ci0.`type` = 'e76b8c7b0a0a0aa70082c9f7c2f9dc64'
GROUP BY cmdb1.`sys_class_name`
ORDER BY cmdb1.`sys_class_name`
So, you actually have access specifically to that dot-walked sys_class_name that's being grouped, but not through the dot-walk. The call to getValue("parent.sys_class_name") is expectedly resolved to the returned column aliased as parent_sys_class_name.
That being said, what you're doing probably should also work, based on user expectations, so you've not done anything incorrect here.

case when sum ( condition )= sum (condition) and condition then using db2 system database

Good night, I am working in DB2 and I have been having some troubles making a query with case when
I have to find a way to make a query to define if a record of some category is valid only if the required fields of the relation are required and have been marked as selected, but in this case some registrys are empty and then I must exclude, I have a query like this:
Select (case (sum(category_id) where required='true' and selected='true') = sum(category_id) where required='true' then 'Yes'
else 'no'
from category_table
The problem, is that in some category the required field are all false (it's means do not exist) then I must put a condition like the sum equal to cero, but i always get a syntax error. I have something like this,
Select (case (sum(category_id) where required='true' and selected='true') = sum(category_id) where required='true' and (count(category_id) where required='true' != 0 ) then 'Yes'
else 'no'
from category_table
I have this problem in db2, saddly I can not put the original query hear because the proxy of my work don't le me pass emails to outside or even login at the web page from there.
I would be grateful for any help.
Have you tried using the VALUE function? if no rows will qualify the case conditions then you'll get Zero in the result.

Codeigniter select_avg('columnname') WHERE thisaverage > x

What I want to do is select items from my database where the average review is greater than 7.
$this->db->select_avg('reviews.overall');
That query selects the average review 'as overall'.
Therefore i assumed i could simply then use
$this->db->where('overall>','7');
This however does not work.
ANy ideas?
Thanks
EDIT
Putting in a space
$this->db->select_avg('reviews.overall');
$this->db->where('overall >','7');
Yields the error
Column 'overall' in where clause is ambiguous
It is ambiguous but how am I now meant to reference it??
Thx
It's writen in the codeigniter user manual too:
$this->db->select_avg(); Writes a "SELECT AVG(field)" portion for your query. As with select_max(), You can optionally include a second parameter to rename the resulting field.
If you enable profiler in CI, you would see, what query does this code generate.
Your code is generated like this:
SELECT AVG(reviews.overall) as reviews.overall FROM ....
Use it like this:
$this->db->select_avg('reviews','overall');
$this->db->from('table name');
$this->db->where('overal >', 7);
$Q = $this->db->get();

LINQ 2 Entities-query is not working, but why?

everyone! ))
Here is code.
var existingEntities = (from record in globalOne.serviceContext.records_out
where record.timestamp.Date == DateTime.Now.Date
select record ).ToList();
It doesn't work.
Another code:
var existingEntities = (from record in globalOne.serviceContext.records_out
where record.timestamp.Day == DateTime.Now.Day
select record ).ToList();
It does work.
So, problem id in next string:
where record.timestamp.**Date** == DateTime.Now.Date
also won't do
where record.timestamp.Date.Equals(DateTime.Now.Date)
But why? I have no clue. "Timestamp" field is dateTime field in MS SQL SERVER.
And - there is NO records in table.
And I almost forgot - what does it mean - "doesn't work".
App just will not reach the breakpoint after that query(first), without any error, without anything.
Thanks.
You can call record.timestamp.Date because EF can't convert it to required expression tree (then convert it to sql command). In fact EF supports limited number of functions and properties, But for DateTime, EF has some good Canonical functions. You can use them in your case, e.g you can use Day(),Month(),Year() functions to solve your problem (see the link).

Resources