Query using Percentage %% [message #661648] |
Sun, 26 March 2017 13:39 |
|
sr8464
Messages: 82 Registered: February 2017 Location: India
|
Member |
|
|
I HAVE TWO TABLE
TABLE_ENTITYENTITY_CODE ENTITY_NAME
SR SR INFO SOLUTION
DP DIGITAL PLANET
TABLE_USERNAME ENTITY_CODE
KESHRI SR
EHTE DP
REZA SR DP
Want query like, if TABLE_USER.ENTITY_CODE = TABLE_ENTITY.ENTITY_CODE then show the value into :LIST_ITEM
When i query for KESHRI it's showing SR INFO SOLUTION and for EHTE it's showing DIGITAL PLANET
But when query for REZA it's showing nothing, i want SR INFO SOLUTION & DIGITAL PLANET into :LIST_ITEM
HOW TO DO THIS???
|
|
|
|
|
|
|
|
Re: Query using Percentage %% [message #661699 is a reply to message #661670] |
Tue, 28 March 2017 11:52 |
|
sr8464
Messages: 82 Registered: February 2017 Location: India
|
Member |
|
|
created 2 viewsCREATE OR REPLACE VIEW VIEW_CALL AS
SELECT DISTINCT
ENTITY_MAST.ENTITY_CODE,
USER_MAST.USER_CODE,
USER_MAST.PASSWORD,
ENTITY_MAST.ENTITY_NAME,
USER_MAST.ENTITY,
REPLACE(USER_MAST.ENTITY, ' ') AS "NO_SPACE"
FROM USER_MAST,ENTITY_MAST
CREATE OR REPLACE VIEW VIEW_CALL1 AS
SELECT DISTINCT
VIEW_CALL.ENTITY_CODE,
VIEW_CALL.USER_CODE,
VIEW_CALL.PASSWORD,
VIEW_CALL.ENTITY_NAME,
VIEW_CALL.ENTITY,
VIEW_CALL.NO_SPACE,
SUBSTR(VIEW_CALL.NO_SPACE,0,2) AS AAA,
SUBSTR(VIEW_CALL.NO_SPACE,3,2) AS BBB,
SUBSTR(VIEW_CALL.NO_SPACE,5,2) AS CCC
FROM VIEW_CALL and thenDECLARE
CURSOR GRP_SR IS
SELECT DISTINCT ROWNUM RN_SR, VIEW_CALL1.ENTITY_CODE||' - '||VIEW_CALL1.ENTITY_NAME AS ENTITY
FROM VIEW_CALL1
WHERE :LOGIN_USER_CODE = VIEW_CALL1.USER_CODE
AND :LOGIN_PASSWORD = VIEW_CALL1.PASSWORD
AND VIEW_CALL1.AAA = VIEW_CALL1.ENTITY_CODE;
CURSOR GRP_DP IS
SELECT DISTINCT ROWNUM RN_DP, VIEW_CALL1.ENTITY_CODE||' - '||VIEW_CALL1.ENTITY_NAME AS ENTITY
FROM VIEW_CALL1
WHERE :LOGIN_USER_CODE = VIEW_CALL1.USER_CODE
AND :LOGIN_PASSWORD = VIEW_CALL1.PASSWORD
AND VIEW_CALL1.BBB = VIEW_CALL1.ENTITY_CODE;
CURSOR GRP_XX IS
SELECT DISTINCT ROWNUM RN_XX, VIEW_CALL1.ENTITY_CODE||' - '||VIEW_CALL1.ENTITY_NAME AS ENTITY
FROM VIEW_CALL1
WHERE :LOGIN_USER_CODE = VIEW_CALL1.USER_CODE
AND :LOGIN_PASSWORD = VIEW_CALL1.PASSWORD
AND VIEW_CALL1.CCC = VIEW_CALL1.ENTITY_CODE;
BEGIN
CLEAR_LIST ('LOGIN_ENTITY_LIST');
FOR I_SR IN GRP_SR LOOP
FOR I_DP IN GRP_DP LOOP
FOR I_XX IN GRP_XX LOOP
ADD_LIST_ELEMENT ('LOGIN_ENTITY_LIST', I_DP.RN_DP, I_DP.ENTITY, I_DP.ENTITY);
ADD_LIST_ELEMENT ('LOGIN_ENTITY_LIST', I_SR.RN_SR, I_SR.ENTITY, I_SR.ENTITY);
ADD_LIST_ELEMENT ('LOGIN_ENTITY_LIST', I_XX.RN_XX, I_XX.ENTITY, I_XX.ENTITY);
END LOOP;
END LOOP;
END LOOP;
END;
1. how to merge both views into 1
2. how to merge ADD_LIST_ELEMENT into 1 so that i use ORDER BY CLAUSE
3. how to set one default value in list item using WHERE CLAUSE OR OTHER example...
code's are well executing but i don't know it's in proper channel or not
TEST CASECREATE TABLE USER_MAST(
USER_CODE VARCHAR(8) NOT NULL,
PASSWORD VARCHAR(20) NOT NULL,
ENTITY VARCHAR(50));
CREATE TABLE ENTITY_MAST(
ENTITY_CODE VARCHAR(2) NOT NULL,
ENTITY_NAME VARCHAR(50));
INSERT INTO USER_MAST VALUES ('MSRDBA','12345','SR DP XP');
INSERT INTO USER_MAST VALUES ('ACC-RN','123','SR');
INSERT INTO USER_MAST VALUES ('DP-KT','XYZ','DP XP');
INSERT INTO ENTITY_MAST VALUES ('SR','SR INFO SOLUTION');
INSERT INTO ENTITY_MAST VALUES ('DP','DIGITAL PLANET');
INSERT INTO ENTITY_MAST VALUES ('XP','XEROX POINT');
SELECT * FROM USER_MAST;
SELECT * FROM ENTITY_MAST;
[Updated on: Tue, 28 March 2017 12:12] Report message to a moderator
|
|
|
Re: Query using Percentage %% [message #661701 is a reply to message #661699] |
Tue, 28 March 2017 12:47 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
sr8464 wrote on Tue, 28 March 2017 12:52
1. how to merge both views into 1
I don't see the purpose of VIEW_CALL1 as VIEW_CALL seems to be VIEW_CALL with additional columns. If you really must combine them, make a third one and union them together, setting the 3 additional columns to NULL.
And if you insist on two or three views, then having distinct in more than one of them is unnecessary.
[Updated on: Tue, 28 March 2017 12:51] Report message to a moderator
|
|
|
|
Re: Query using Percentage %% [message #661716 is a reply to message #661708] |
Wed, 29 March 2017 03:37 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
You can't work out how to merge 2 views when one of them only queries the other?
Replace the from of VIEW_CALL1 with the whole select of VIEW_CALL - i.e. nest it so you don't have to do the replace 4 times.
As for merging the cursors - OR is a wonderful thing.
And I don't know what you think you're doing with rownum there but what you've got will give rownum of 1 for each query if you use the login MSRDBA.
|
|
|
|
|
|
Re: Query using Percentage %% [message #661808 is a reply to message #661805] |
Mon, 03 April 2017 07:10 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
You don't need to specify user_code twice, and if that's the view I'm not sure why you're specifying it at all - it won't work for other users.
You probably don't want to set initial value programatically - you'd have to do it in when-new-record-instance and doing so would immediately change the record status to insert - meaning forms thinks there's changes that need saving and will prompt the users if they try to leave the record in any way. If you default it in when-validate-record or pre-insert (so as part of the save process), you'll avoid that problem.
|
|
|
|
Re: Query using Percentage %% [message #661953 is a reply to message #661952] |
Fri, 07 April 2017 05:20 |
cookiemonster
Messages: 13963 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Pretty sure it can simply be this:
SELECT DISTINCT ROWNUM RN_SR, ENTITY_CODE ||' - '|| ENTITY_NAME AS ENTITY_SHOW
FROM ENTITY_MAST, USER_MAST
WHERE USER_CODE = :LOGIN_USER_CODE
AND :LOGIN_PASSWORD = PASSWORD
AND ENTITY_CODE = SUBSTR(REPLACE(ENTITY, ' '), 0, 2);
The main query is already selecting from user_mast, so having a sub-query to get the same user_mast record is pointless.
The above only does the equivalent of GRP_SR, what about the other 2?
|
|
|
|