Hi guys,
I have a task to check the mandatory columns whether it is NULL or blank and stored them into exception table.
Here is the query statement for one particular column and it's working.
I have to check NULL or blank for like 20-30 other columns in LOAD_TABLE and If I repeat those query 20-30 times it wouldn't look very nice in the stored proc.
Hence I was wondering whether I could make the column name dynamic.
something like:
Thanks in advance!
I have a task to check the mandatory columns whether it is NULL or blank and stored them into exception table.
Here is the query statement for one particular column and it's working.
Code:
UPDATE LOAD_TABLE
SET ERR_F = 'W'
OUTPUT INSERTED.*,
'B2',
GETDATE(),
'Warning : EC1 Null or blank non-nullable field : [SECC]',
1
INTO LOAD_EXCEPTION
WHERE
SECC = '' OR SECC IS NULL
I have to check NULL or blank for like 20-30 other columns in LOAD_TABLE and If I repeat those query 20-30 times it wouldn't look very nice in the stored proc.
Hence I was wondering whether I could make the column name dynamic.
something like:
Code:
UPDATE LOAD_TABLE
SET ERR_F = 'W'
OUTPUT INSERTED.*,
'B2',
GETDATE(),
'Warning : EC1 Null or blank non-nullable field :' + Dynamic_column_name,
1
INTO LOAD_EXCEPTION
WHERE
(SECC = '' OR SECC IS NULL) OR (COLUMN2 = '' OR COLUMN2 IS NULL) OR ...
Thanks in advance!