Forum Discussion
mjsystemss
Sep 14, 2024Copper Contributor
HELP WITH MY WHERE CLAUSE REQUIREMENT
Hello , I need help with examining this query. I have this query below and my requirements. The First Requirement is 1. If appselection !='notice to process' and notetxt is NULL in last month show...
rodgerkong
Sep 15, 2024Iron Contributor
Do you need two different result set? With requirement 1, show acct and notetext. With requirement 2, show acctid.
In your SQL sample, WHERE clause has two same parts of conditions that split by 'OR', what is the purpose?
Give some sample rows and show the result your want, will supply more help to understand your question.
In your SQL sample, WHERE clause has two same parts of conditions that split by 'OR', what is the purpose?
Give some sample rows and show the result your want, will supply more help to understand your question.
mjsystemss
Sep 15, 2024Copper Contributor
The Two conditions are to produce one result set.
The resulting table should be like this;
ACCTID NDATE NOTETXT APPSTATUS
000001 02/06/2023 FIRE INCIDENT NO NOTICE
000002 03/09/2024 MINOR FIRE NOTICE TO PROCESS
000003 09/09/2024 NO INCIDENT NOTICE TO PROCESS
000004 03/07/2024 NO NOTICE
- rodgerkongSep 15, 2024Iron ContributorWhat are the structures of TABLEA and EXAMPLE? And give some sample data in those 2 tables.
Base on the sample data, what is the result you want?- mjsystemssSep 15, 2024Copper ContributorThe Table I have given is a consolidated Table and the table should be filtered based on the requirements below.
acctid number
ndate varchar2(20)
Notetxt Varchar2(50)
AppStatus Varchar2(100)
1. If appstatus !='notice to process' and no notetext in last month show acct and no txt notes
2. if appstatus='notice to process' and no notetext in one month show the results (acctid)- mjsystemssSep 15, 2024Copper ContributorCREATE TABLE TABLEA
(ACCTID NUMBER(15) PRIMARY KEY,
NDATE Varchar2(25),
NOTETXT VARCHAR2(50),
APPSTATUS VARCHAR2(50));
ASSUME DATA IS INSERTED using below insert sttements.
Insert into TableA Values (acctid,ndate,notetxt,AppStatus)
(1,'2/6/2023','fire incident', ‘no notice’);
Insert into TableA Values
(2,'3/9/2024','minor fire', ‘notice to process’);
Insert into TableA Values
(3,'9/9/2024','no incident', ‘notice to process’);
Insert into TableA Values
(4,'3/7/2024',' ', ‘notice to process’);
--Below is the select statement
SELECT ACCTID, NDATE,NOTETXT,APPSTATUS
FROM TABLEA
WHERE b.appselection='notice to process' AND (a.notetxt IS NULL OR TO_DATE(a.ndate, 'mm/dd/yyyy')<=ADD_Months(SYSDATE,-1))) OR b.appselection='notice to process' AND (a.notetxt IS NULL OR TO_DATE(a.ndate,'mm/dd/yyyy')<=ADD_MONTHS(sysdaate,-1)));
Requirement;
I need a where clause that meets the below requirements
If appstatus !='notice to process' and no notetext in last month show acct and no txt notes.
if appstatus='notice to process' and no notetext in one month show the results (acctid).
I need to know if my where clause addresses my requirement well.