how to Handle not in Function

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
arasan
Participant
Posts: 44
Joined: Wed Nov 30, 2005 3:54 am
Contact:

how to Handle not in Function

Post by arasan »

I am using NOT IN function but the result is varing when i implement the funtion through datastage where us when i try to do in sql server using NOT in function i am getting the correct result.

can any one suggest me where i went wrong

If (SRVC_TPY_CD_ID<>'N' or SRVC_TPY_CD_ID<>'A' orSRVC_TPY_CD_ID<>'Z' or SRVC_TPY_CD_ID<>'I' 0r SRVC_TPY_CD_ID<>'P' ) and len(trim(SAI_NBR_ID)>0 then NON_JOB_HRS else 0

if i try to incorporate the above derivation the result is varying what is got in sqlserver and in datastage.
jhmckeever
Premium Member
Premium Member
Posts: 301
Joined: Thu Jul 14, 2005 10:27 am
Location: Melbourne, Australia
Contact:

Post by jhmckeever »

arasan,

If I'm following your post correctly you're trying to emulate a SQL 'NOT IN' clause using a succession of OR'd clauses. To get the logical equivalent of a NOT IN using this method you must AND your clauses together.

Code: Select all

If (
   SRVC_TPY_CD_ID<>'N' AND SRVC_TPY_CD_ID<>'A' AND
   SRVC_TPY_CD_ID<>'Z' AND SRVC_TPY_CD_ID<>'I' AND
   SRVC_TPY_CD_ID<>'P' )  ...
There are also a few ways of achieving the same result using BASIC functions.

HTH :)
J.
Last edited by jhmckeever on Wed Jan 03, 2007 6:16 am, edited 1 time in total.
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
arasan
Participant
Posts: 44
Joined: Wed Nov 30, 2005 3:54 am
Contact:

Post by arasan »

Thanks for the reply but i tried with AND function also i am not getting the exact result is there any other function in datastage to do the NOT IN function
jhmckeever
Premium Member
Premium Member
Posts: 301
Joined: Thu Jul 14, 2005 10:27 am
Location: Melbourne, Australia
Contact:

Post by jhmckeever »

Perhaps you could post the SQL you are trying to emulate?

Note that ...

Code: Select all

SRVC_TPY_CD_ID<>'N' AND SRVC_TPY_CD_ID<>'A' AND 
SRVC_TPY_CD_ID<>'Z' AND SRVC_TPY_CD_ID<>'I' AND 
SRVC_TPY_CD_ID<>'P' 
... is the same as

Code: Select all

WHERE SRVC_TPY_CD_ID NOT IN ('N','A','Z','I','P')
<b>John McKeever</b>
Data Migrators
<b><a href="https://www.mettleci.com">MettleCI</a> - DevOps for DataStage</b>
<a href="http://www.datamigrators.com/"><img src="https://www.datamigrators.com/assets/im ... l.png"></a>
arasan
Participant
Posts: 44
Joined: Wed Nov 30, 2005 3:54 am
Contact:

Post by arasan »

yes,as you have mentioned i used the same in the SQL.

when i fire the query it is resulting the result as 5.8 in the sql.same thing through datastage it is resulting sa 20.6
Edwink
Participant
Posts: 47
Joined: Sat Aug 19, 2006 4:57 am
Location: Chennai

Post by Edwink »

Arasa,
try to use count function
count(",N,A,I,P,Z,","SRVC_TPY_CD_ID")<1
If there are matches the output will be zero - which should solve your problem. 8)
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Try by trimming the fields first before doing your inequality check. There might be a trailing space or two. Make those columns varchar.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Here's how I would do it. The Index() function is very efficient. I am assuming that SRVC_TPY_CD_ID is Char(1) data type.

Code: Select all

If Index("NAPIZ",InLink.SRVC_TPY_CD_ID,1) = 0 And Trim(InLink.SAI_NBR_ID) > " " Then NON_JOB_HRS Else 0 
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
arasan
Participant
Posts: 44
Joined: Wed Nov 30, 2005 3:54 am
Contact:

Post by arasan »

Thanks for all your replies ,i spoke to the clinent and went for the equal to function then the result was accurate.

previous

i was using srvc_typ_cd_id<>'A' or srvc_typ_cd_id<>'Z' ......

existing

except (AZNIP) remaining srvc_typ_cd_id i took and implemented the equal to function in thje derivation.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

arasan wrote:previous

i was using srvc_typ_cd_id<>'A' or srvc_typ_cd_id<>'Z' ......
This would have worked more better with an 'AND' between them, not an 'OR'. This expression gets you everything as not only are all other letters not equal to 'A' or 'Z' but 'A' is not equal to 'Z' (so it gets counted) and vice versa. :shock:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply