× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I’m working on an SQL statement for DB2/400 (OS release V5R3). I have
several history tables each with an effective from timestamp (EFFFROMTS)
and effective thru timestamp (EFFTHRUTS). The purpose of my script is
to compare two rows (within the same table) and report the column name,
old value and new value, when a difference is found.

I feel I’m close with the script found below but, I can’t figure a
way to convert the value of COLUMN_NAME into a usable column name.

Is there a function available to convert a string into a column name?
My attempt of:

AND NOT T3.(T1.COLUMN_NAME) = T2.(T1.COLUMN_NAME)

does not work, but I think it gives you an idea of what I’m trying to
accomplish.

If this is not going to work, does anyone have another approached I
might try?

Thanks
Allen

SELECT T1.COLUMN_NAME
, CAST(T2.(T1.COLUMN_NAME) AS CHAR(30)) AS OLD_VALUE
, CAST(T3.(T1.COLUMN_NAME) AS CHAR(30)) AS NEW_VALUE ,
T3.EFFFROMTS

FROM SYSIBM.SQLCOLUMNS T1
INNER JOIN (SELECT * FROM EMPLOYEE
WHERE EMPNUM = :PARM_EMPNUM
AND EFFFROMTS BETWEEN :PARM_FROMTS
AND :PARM_THRUTS
ORDER BY EFFFROMTS) T2
INNER JOIN (SELECT * FROM EMPLOYEE
WHERE EMPNUM = :PARM_EMPNUM
AND EFFFROMTS BETWEEN :PARM_FROMTS
AND :PARM_THRUTS
ORDER BY EFFFROMTS) T3 ON RRN(T3) = (RRN(T2) + 1) AND
NOT T3.(T1.COLUMN_NAME) = T2.(T1.COLUMN_NAME)
WHERE T1.TABLE_SCHEM = :PARM_SCHEMA
AND T1.TABLE_NAME = 'EMPLOYEE' AND NOT T1.COLUMN_NAME IN
('EFFFROMTS', 'EFFTHRUTS') ;


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.