Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent help needed with SQL query

Status
Not open for further replies.

tranz125

IS-IT--Management
Aug 29, 2005
1
US
Hello,

I have the following scenario please help:

i have my source data as::

DEL STATUS TIMESTAMP EVENT

D1 ACT JAN 13 audit
D1 CURE JAN 23 CURRENT



MY TARGET TABLLE MUST HAVE DATA IN THSI FORMAT:

DEL STATUS EFFECTIVE_DATE END_DATE

D1 ACT JAN 13 JAN 23
D1 CURE JAN23 NULL


I am trying to write a SQL to implement it please help me or give your suggestions to implement it.


Thanks
 
You did never explain how to find out end_date...

Maybe you want something like this?

SELECT del,
status,
timestamp AS effective_date,
CASE WHEN status = 'ACT' THEN
(SELECT timestamp FROM sourcedata
WHERE del = sd.del
AND status = 'CURE')
ELSE NULL END AS end_date
FROM sourcedata AS sd


BTW, TIMESTAMP is a reserved word in ANSI SQL. Consider renaming that column.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top