I want to check for the is not null constraint for multiple columns in a single SQL statement in the WHERE
clause, is there a way to do so?
Also I don't want want to enforce the NOT NULL
type constraint on the column definition.
SELECT * FROM AB_DS_TRANSACTIONS
WHERE FK_VIOLATION IS NULL
AND TRANSACTION_ID NOT IN(
SELECT distinct TRANSACTION_ID FROM AB_TRANSACTIONS)
AND COUNTRY_ID IS NOT NULL
AND GEO_CUST_COUNTRY_ID IS NOT NULL
AND INVOICE_DATE IS NOT NULL
AND ABB_GLOBALID IS NOT NULL
AND SALES_ORG_ID IS NOT NULL
AND DIST_ID IS NOT NULL
AND CUSTOMER_ID IS NOT NULL
AND REPORT_UNIT_ID IS NOT NULL
AND CURR_INVOICE IS NOT NULL
AND DIVISION_CODE IS NOT NULL
So instead of using IS NOT NULL again and again I want to simplify things
We can add NOT NULL constraint on multiple columns in one table. NOT NULL constraint allows duplicate values. If we defined a column as NOT NULL while inserting or updating values on table, we must and should give value to that specified column. Not Null Constraint allow duplicate values.
"I want to have a not null constraint on all 3 name columns" - simply run "alter table employee modify (<column name> not null)" for each column. 2. Instead of using "NVL(FIRST_NAME,NVL(MIDDLE_NAME,LAST_NAME))", you could just do "COALESCE(FIRST_NAME,MIDDLE_NAME,LAST_NAME)".
Filtering NULL from Multiple Columns This can be performed with this simple statement using AND with multiple comparison operators: SELECT primary_author, published_date, title FROM books WHERE ( primary_author IS NOT NULL AND published_date IS NOT NULL );
SELECT * FROM AB_DS_TRANSACTIONS
WHERE COALESCE(COUNTRY_ID,GEO_CUST_COUNTRY_ID,INVOICE_DATE,ABB_GLOBALID,SALES_ORG_ID,DIST_ID,CUSTOMER_ID,REPORT_UNIT_ID,CURR_INVOICE,DIVISION_CODE) IS NOT NULL
You can use
SELECT * FROM table1
WHERE NOT (Column1 IS NULL OR
Column2 IS NULL OR
Column3 IS NULL OR
Column4 IS NULL
IS NOT NULL)
As per OP comment, Updating answer
INSERT INTO Table_A
SELECT column1, column2, column3,column4
FROM Table_B
WHERE NOT (Column1 IS NULL OR
Column2 IS NULL OR
Column3 IS NULL OR
Column4 IS NULL
IS NOT NULL);
I am able to reduce 50 chars approx
SELECT * FROM AB_DS_TRANSACTIONS
WHERE
FK_VIOLATION IS NULL
AND TRANSACTION_ID NOT
IN(SELECT distinct TRANSACTION_ID FROM AB_TRANSACTIONS)
AND
NOT (
COUNTRY_ID IS NULL
OR GEO_CUST_COUNTRY_ID IS NULL
OR INVOICE_DATE IS NULL
OR ABB_GLOBALID IS NULL
OR SALES_ORG_ID IS NULL
OR DIST_ID IS NULL
OR CUSTOMER_ID IS NULL
OR REPORT_UNIT_ID IS NULL
OR CURR_INVOICE IS NULL
OR DIVISION_CODE IS NULL
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With