How to use the list the member detail AND order date by user input using WHERE condition? - oracle11g

I want to show the member detail by input member id then input order date greater than current date SO
I can list the all member detail but after AND condition,
it give me following error: 00933. 00000 - "SQL command not properly ended"
SELECT G_MEMBER.MEMBER_ADDRESS,
G_ORDER.PAYMENT_TYPE,G_ORDER.ORDER_DATE,G_ALBUM.ALBUM_NAME
FROM G_MEMBER
INNER JOIN G_ORDER
ON G_MEMBER.MEMBER_ID = G_ORDER.MEMBER_ID
INNER JOIN G_ALBUM
ON G_MEMBER.MEMBER_ID = G_MEMBER.MEMBER_ID
WHERE G_MEMBER.MEMBER_ID= '&MEMBER_ID'
AND G_ORDER.ORDER_DATE='&ENTER_DATE' > CURRENT_DATE; code here

Related

Oracle Apex Select List LOV conditional query

I have an Editable Interactive Grid (for product_sale table) with a Select List (to select a product) in Oracle Apex 20.2 app.
Currently I'm using below query to populate this list of values.
SELECT productName,productId FROM product WHERE productAvailability = 'Y'
There are a few products that I need to set the productAvailability as 'N'. When I made this change, Interactive Grid of product_sale shows productId instead of the productName.
What I need to achieve is, only show products with productAvailability = 'Y' for new records (when going to add new record in to the table by clicking Add Row button) and for the old records show the productName of the selected product regardless the productAvailability.
Table Structure
Sample Data
Interactive Grid View
How could I achieve this?
You can achieve this using the "cascading list of values" option in the column settings. Let me illustrate with an example on the EMP sample table - you should be able to translate this to your own code:
Situation: BLAKE can not be selected as manager for any other employees than the one he is already manager for.
This would be the select:
SELECT ename, empno FROM emp WHERE ename != 'BLAKE'
As expected, for records that have BLAKE as manager, the MGR column will display the id because the value is not in the result set of the select list query. This is the behaviour you are seeing.
The solution has 2 steps:
Union the query with a query that has the value of the current row. I have rewritten the query using a CTE.
WITH all_mgr(dv, rv) AS
(SELECT ename, empno FROM emp WHERE ename != 'BLAKE'
UNION
SELECT m.ename, m.empno
FROM emp e
JOIN emp m ON e.mgr = m.empno
WHERE e.ename = :ENAME
)
SELECT dv, rv FROM all_mgr
Make sure column ename from the current row is bind to :ENAME. In "Cascading List Of Values" set both "Parent Column" and "Items to Submit" to ENAME. Now the select list will take the current row value for :ENAME and the list of values will include 'BLAKE' for users that have 'BLAKE' as a manager.

How to implement NOT EXISTS in OPEN QUERY statement in PROGRESS 4GL - OpenEdge 10.2A

I want to create a browse such that it will show all the records from one table if the values of a field do NOT exist in another table.
It is possible to get the records using SQL as:
SELECT myField FROM pub.myTable WHERE
NOT EXISTS (SELECT myField FROM pub.myTable2 WHERE myTable2.myField=myTable.myField)
It is also possible using 4GL as:
FOR EACH myTable WHERE
NOT CAN-FIND(FIRST myTable2 WHERE myTable2.myField=myTable.myField)
The problem is when I put this query in a browse as:
OPEN QUERY myBrowse
FOR EACH myTable WHERE
NOT CAN-FIND(FIRST myTable2 WHERE myTable2.myField=myTable.myField)
it gives an error message
CAN-FIND is invalid within an OPEN QUERY. (3541)
The question is, is it possible to write such an OPEN QUERY statement?
I didn't come up with this, Steve Moore shared it on https://community-archive.progress.com/forums/00026/27143.html
define temp-table ttNoOrder
field field1 as char.
create ttNoOrder.
define query q1 for Customer, Order, ttNoOrder.
open query q1 for each Customer no-lock,
first Order of Customer outer-join no-lock,
first ttNoOrder where not available(Order).
get first q1.
repeat while not query-off-end("q1"):
display Customer.CustNum Customer.Name available(Order).
get next q1.
end.
Works even with dynamic queries:
DEFINE TEMP-TABLE ttNoOrder
FIELD field1 AS CHARACTER .
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
CREATE ttNoOrder.
CREATE QUERY hQuery .
hQuery:SET-BUFFERS (BUFFER Customer:HANDLE,
BUFFER Order:HANDLE,
BUFFER ttNoOrder:HANDLE) .
hQuery:QUERY-PREPARE ("for each Customer no-lock, ~
first Order of Customer outer-join no-lock, ~
first ttNoOrder where not available(Order)") .
hQuery:QUERY-OPEN() .
hQuery:GET-FIRST () .
REPEAT WHILE NOT hQuery:QUERY-OFF-END:
DISPLAY Customer.CustNum FORMAT ">>>>>>>>>9" Customer.Name AVAILABLE(Order).
hQuery:GET-NEXT ().
END.

Entity Framework using SQL Server datastore modelling a one-to-many relationship

Can I get some help diagnosing the following?
IQueryable<MyComponentsViewModel> vcvm = from v1 in pg.MyComponents
join item in Items on v1.Item equals item into vc
select new MyComponentsViewModel
{ Cost = item.Cost };
The following error appears:
Error CS1941: The type of one of the expressions in the join clause is
incorrect. Type inference failed in the call to 'GroupJoin'.
Is this error state occuring as item is not the same type as v1.Item?
The keys are shown below
ALTER TABLE [dbo].[MyComponents] WITH CHECK ADD CONSTRAINT
[FK_MyComponents_Items] FOREIGN KEY([ItemId])
REFERENCES [dbo].[Items] ([Itemid])
GO
ALTER TABLE [dbo].[MyComponents] CHECK CONSTRAINT [FK_MyComponents_Items]
I assume like, you need inner join and while you doing equals you need to use their matching column Ids to filter records like below
IQueryable<MyComponentsViewModel> vcvm =
from myComp in pg.MyComponents
join item in Items on myComp.ItemId equals item.Id
select new MyComponentsViewModel { Cost = item.Cost };
I was able to get it to work.
There was an ambiguity between an action named Items. Fully specify the namespace resolved this.
Additionally I had to add the statement "from subitem in vc.DefaultIfEmpty"
I'm still working to learn the full semantics of this
IQueryable<MyComponentsViewModel> vcvm =
from v1 in pg.MyComponents
join item in pg.Items on v1.Item equals item into vc
from subitem in vc.DefaultIfEmpty()
select new MyComponentsViewModel { Cost = subitem.Cost };

start with prior reference on last select

I have a problem while inserting based on select query
I have a schema in the database with a parent-child relationship that looks like the following
A
B
C
G
L
F
C
G
L
Notice how Element c is reused, because it´s aviable twice with different parent id, but element g is only aviable once, since the id of c is the same in both cases. The select prints everything as expected with the following query
select id,
parent_id,
label
from table
start with parent_id is null
connect by nocycle prior id = parent_id
order siblings by sort
i am having around 2500 elements in this table, but in the end around 4000 are displayed because a few elemnts should be displayed multiple times at different places.
So, to identify both, the first and second g as unique elements, i have written the following insert statement
insert into other_tale (id, parent_id, label)
select create_id new_id,
prior ???,
label,
from table
start with parent_id is null
connect by nocycle prior id = parent_id
order siblings by sort;
Here i am calling a procedure to generate a new id for each raw that has been found. Now i am stuck at the part where i do recieve the new id of the parent element. I know that i can refer to the prior parent_raw in the table beeing select, but am i able to somehow refer to the column new_id of the parent_element in the select?
Create a package with 1 associative array id_cache and 2 functions: f_clear_cache and f_generate_id.
f_clear_cache deletes the cached ids - id_cache.delete.
f_generate_id takes id as argument and returns the new_id
check if the new_id was already generated - id_cache.exists(id)
if not, generate the new_id and cache it - id_cache(id) := new_id
return new_id - return id_cache(id)
finally use the function in your sql statement
insert into other_tale (id, parent_id, label)
select my_package.f_generate_id(id),
my_package.f_generate_id(parent_id),
label
...
note: do not forget to call f_clear_cache when you want to generate new set of ids within the same session.

SQLITE getting trigger to check against table1 and insert into table2

I have a reservation table which the user will insert records into.
The User does not select the car just the type.
Once the record is inserted I want some triggers to do the following:-
The date and vehicle combination to a log file the data and vehicle are UNIQUE(date,car) so the same reservation cannot be made twice therefore a car cannot be double booked.
SO my issue is how do I now get the trigger to select the next available car of that type?
I can get it to select the next car by just saying Car.carid != Log.carid but that is not using the date as a second check so I could not then use the vehicle on another date.
Simply putting AND between the check doesnt work meaning
WHERE Car.carid != Log.carid AND Reservation.date != C.datewhen
Some guidance would be much appreciated!
I think this query is what you are after...
SELECT MIN(c.carid)
FROM all_cars c
WHERE c.type = 'CAR TYPE'
AND NOT EXISTS
(SELECT 1
FROM reservation r
WHERE r.date = 'THE DATE'
AND r.carid = c.carid)
If the query returns a NULL value then no cars are available.
Or you could take off the MIN and just use the first record returned.

Resources