WHERE DATE in (StringParameter) in DB2 Stage

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
gauravrb
Participant
Posts: 28
Joined: Wed Dec 27, 2006 11:31 pm
Location: Mumbai

WHERE DATE in (StringParameter) in DB2 Stage

Post by gauravrb »

The SQL query required in DB2 Stage is

Code: Select all

select 
          BUSINESS_DATE 

from saggbp2.etl_business_time 

where BUSINESS_DATE in (#BD#)
#BD# - Is parameter containing comma separated values of date of type string.
Eg:- (2008-11-26,2008-11-28,2006-01-01).

But it did not work in DB2 stage. The Job aborted.

I tried coverting the source Date in to string by using VARCHAR() function and using the following query

Code: Select all

select 
          BUSINESS_DATE 

from saggbp2.etl_business_time 

where VARCHAR(BUSINESS_DATE) in ('#BD#')
The job ran but did not fetch any records inspite of having the date in the list of values. I guess it is taking the enitire parameter as one string.
Is there any way around to make this work in DB2 stage itself?

Thanks
Gaurav.
bikan
Premium Member
Premium Member
Posts: 128
Joined: Thu Jun 08, 2006 5:27 am

Post by bikan »

try by enclosing date into single quote.......& using or function
gauravrb
Participant
Posts: 28
Joined: Wed Dec 27, 2006 11:31 pm
Location: Mumbai

Post by gauravrb »

bikan wrote:try by enclosing date into single quote.......& using or function
Thanks.

I tried enclosing it in single quotes as well. But the stage i guess considers the entire parameter as string and does not fect any records.

I am not sure how can we use or function here because i will not be knowing the how many values i will be receiving via parameter.
bikan
Premium Member
Premium Member
Posts: 128
Joined: Thu Jun 08, 2006 5:27 am

Post by bikan »

As per me tour query should look like

select
BUSINESS_DATE

from saggbp2.etl_business_time

where BUSINESS_DATE in ('2008-11-26','2008-11-28','2006-01-01')..b
gauravrb
Participant
Posts: 28
Joined: Wed Dec 27, 2006 11:31 pm
Location: Mumbai

Post by gauravrb »

bikan wrote:As per me tour query should look like

select
BUSINESS_DATE

from saggbp2.etl_business_time

where BUSINESS_DATE in ('2008-11-26','2008-11-28','2006-01-01')..b
Thanks.

It works when we harcode the values.
But the problem is when we use it as parameter.
Scope
Premium Member
Premium Member
Posts: 63
Joined: Wed Jun 06, 2007 6:38 am
Location: Chennai

Post by Scope »

try this

Code: Select all

select 
          BUSINESS_DATE 

from saggbp2.etl_business_time 

where BUSINESS_DATE in ('#BD#') 

pass the value :arrow: 2008-11-26','2008-11-28','2006-01-01 in the parameter
Kumarez
gauravrb
Participant
Posts: 28
Joined: Wed Dec 27, 2006 11:31 pm
Location: Mumbai

Post by gauravrb »

Scope wrote:try this

Code: Select all

select 
          BUSINESS_DATE 

from saggbp2.etl_business_time 

where BUSINESS_DATE in ('#BD#') 

pass the value :arrow: 2008-11-26','2008-11-28','2006-01-01 in the parameter

Tried it. Did not work. Got the following error.
DB2_UDB_Enterprise_0,0: Error Idx = 9;
DB2Driver Embedded SQL message: SQL0180N The syntax of the string representation of a datetime value is
incorrect. SQLSTATE=22007
;
sqlcode = -180;
sqlstate = 22007
Scope
Premium Member
Premium Member
Posts: 63
Joined: Wed Jun 06, 2007 6:38 am
Location: Chennai

Post by Scope »

i think your parameter 'BD' datatype is date.change the parameter type to string.
Kumarez
gauravrb
Participant
Posts: 28
Joined: Wed Dec 27, 2006 11:31 pm
Location: Mumbai

Post by gauravrb »

Scope wrote:i think your parameter 'BD' datatype is date.change the parameter type to string.
No.
The parameter data type is String only.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Your job parameter needs to have the intermediate quote characters.

Code: Select all

'2008-11-26','2008-11-28','2006-01-01'
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
gauravrb
Participant
Posts: 28
Joined: Wed Dec 27, 2006 11:31 pm
Location: Mumbai

Post by gauravrb »

ray.wurlod wrote:Your job parameter needs to have the intermediate quote characters.

Code: Select all

'2008-11-26','2008-11-28','2006-01-01'
...
Hi Ray,

Using the code

Code: Select all

select 
          BUSINESS_DATE 

from saggbp2.etl_business_time 

where BUSINESS_DATE in (#BD#) 
Where

BUSINESS_DATE - Of Type Date
#BD# - Of Type String

I pass The value for the Parameter #BD# having intermediate quote characters.

Code: Select all

'2008-11-26','2008-11-28','2006-01-01'
The job aborts giving the followinng Error

Code: Select all

DB2_UDB_Enterprise_0: Error Idx = 5;
DB2Driver Embedded SQL message: SQL0206N  "€8" is not valid in the context where it is used.  SQLSTATE=42703
;
sqlcode = -206;
sqlstate = 42703
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Are you SURE that that message is coming from the date column? The mention of "€8" suggests that something else may be involved.

It may also be that null is not being handled gracefully.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
thumati.praveen
Participant
Posts: 106
Joined: Wed Oct 04, 2006 5:21 am

Post by thumati.praveen »

Hi,

when we right clik on the stage and view the data it is allowing.But when I ran the job I got following error.

error code is

DB2_UDB_Enterprise_1: Error Idx = 5;
DB2Driver Embedded SQL message: SQL0401N The data types of the operands for the operation "IN" are not
compatible. SQLSTATE=42818
;
sqlcode = -401;
sqlstate = 42818

Thanks,
Praveen
Post Reply