Lookup without key

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
prasad111
Premium Member
Premium Member
Posts: 173
Joined: Fri May 19, 2006 10:53 am

Lookup without key

Post by prasad111 »

I have two tables

source table has

-----------------------------------------
address1 | city | state | zip
------------|---------|-------|-----------
123 main | newark| NJ | 12310
3434 | sanjose| CA | 54540
1232 | ASJK | AI | 4454550
-----------------------------------------------

NOTE: In the above table AI stands for one of the foreign country
the lookup table has all the state columns

stt_cd
--------
AE
CA
NJ
.
.
..
all the states in USA are mentioned

Now In my target table, if there are any state outside USA in the lookup has to be replaced with **, so for above example the output should be
-----------------------------------------
address1 | city | state | zip
------------|---------|-------|-----------
123 main | newark| NJ | 12310
3434 | sanjose| CA | 54540
**** | *** | ** | *****
-----------------------------------------------

NOTE: there is no key column in source and lookup and I should not hardcode the 52 states in column derivation inside the transformer.

how can I achive this output in DataStage, is it possible by an SQL query atleast....
please give some ideas.

Regards
Prasad
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

You would have just the US states in the lookup. You would add the * to the output data in the transformer when a lookup row is not found. There is no reason to try and bring back ** records from the lookup when you can generate ** strings in the transformer.
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

How can you do a lookup without a key ?

- Create a hashed file from your lookup table with stt_cd as key (Use this as a lookup)
- Now when you dont find a lookup replace with '**' else let the column flow through
Ex : if LookUp.NOTFOUND then '**' else SourceTable.State
Get back if have problems doing this.
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
prasad111
Premium Member
Premium Member
Posts: 173
Joined: Fri May 19, 2006 10:53 am

Post by prasad111 »

narasimha wrote:How can you do a lookup without a key ?

- Create a hashed file from your lookup table with stt_cd as key (Use this as a lookup)
- Now when you dont find a lookup replace with '**' else let the column flow through
Ex : if LookUp.NOTFOUND then '**' else SourceTable.State
Get back if have problems doing this.
I tried like this, i generated it as a key and in column derivation I used it as,

if (SourceLink.State <> LookupLink.STT_CD) then '**' Else SourceLink.State

but this is not working
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

Have you linked the key from the hashed file lookup to the source table column?

Then use this

Code: Select all

if LookupLink.NOTFOUND then '**' Else SourceTable.State 
Last edited by narasimha on Wed Nov 01, 2006 11:08 pm, edited 1 time in total.
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
prasad111
Premium Member
Premium Member
Posts: 173
Joined: Fri May 19, 2006 10:53 am

Post by prasad111 »

narasimha wrote:Have you linked the key from the hashed file lookup to the source table column?

They use this

Code: Select all

if LookupLink.NOTFOUND then '**' Else SourceTable.State 
It is working, it was mistake from my side.

Thanks a lot
narasimha
Charter Member
Charter Member
Posts: 1236
Joined: Fri Oct 22, 2004 8:59 am
Location: Staten Island, NY

Post by narasimha »

Can you mark it as resolved :roll:
Narasimha Kade

Finding answers is simple, all you need to do is come up with the correct questions.
Post Reply