Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Imitating procedural language using SQL - forum topic by abin

$
0
0

Hi,
 
I have this requierement to set a flag based on multiple logic. Main problem is flag needs to be set based on value from a previous record in the order. Here is an example. Last coulmn gives the logic to set the flag.
 

Customer

Entry_Date

Action

From

To

Flag

 

INBUGHUJIK

2/1/2010 10:00:00.000000

WENT-LST

Bldg1 

Bldg1 

N

Flag is N because Action is WENT-LST

INBUGHUJIK

2/4/2010 08:12:00.000000

FACT-OUT

Bldg1 

Bldg1 

N

Flag is N because From = To

INBUGHUJIK

2/12/2010 12:13:00.000000

FACT-IN 

Bldg2 

Bldg3

N

Flag is N because previous record has From = To

INBUGHUJIK

2/13/2010 11:18:00.000000

COME-FST

Bldg2 

Bldg2 

N

Flag is N because previous record has From = To

INBUGHUJIK

2/25/2010 08:51:00.000000

WENT-LST

Bldg2 

Bldg2 

N

Flag is N because Action is WENT-LST

INBUGHUJIK

2/26/2010 18:06:00.000000

FACT-OUT

Bldg2 

Bldg3

Y

Flag is Y because previous record has Action as WENT-LST and From <> To

INBUGHUJIK

4/19/2010 10:01:00.000000

FACT-OUT

Bldg2 

Bldg4 

Y

Flag is Y because one of previous record has Action as WENT-LST and From <> To and previous record has flag Y

INBUGHUJIK

4/21/2010 22:56:00.000000

FACT-IN 

Bldg3 

Bldg3

N

Flag is N because previous record has From = To

Any one have any idea on how to achieve this using SQL alone?
 
Regards,
Abin.

Forums: 

Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>