Parameterising a WHERE clause

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
thebird
Participant
Posts: 254
Joined: Thu Jan 06, 2005 12:11 am
Location: India
Contact:

Parameterising a WHERE clause

Post by thebird »

Hi,

I want to pass an SQL query as a parameter in a job, but I am getting a fatal error when I do so. I believe that DS is not accepting the quotes that I give to define WHERE clause.

My where clause is :
WHERE CNSM_END_DT = TO_DATE('2999-12-31','YYYY-MM-DD')

The fatal error that I get is :

ConsumerDbTgt: GenericQuery:esqlErrorHandler
Prepare failed for: GenericStmt_1
query is: SELECT CNSM_ID,SRC_CNSM_CD AS src_cnsm_cd,SRC_APPL_CD AS src_appl_cd FROM CONSUMER WHERE CNSM_END_DT = TO_DATE(2999-12-31, YYYY-MM-DD) ORDER BY src_appl_cd ASC,src_cnsm_cd ASC
sqlcode is: -904
esql complaint: ORA-00904: "DD": invalid identifier

I can see in this error message that the quotes that I had given for TO_DATE('2999-12-31','YYYY-MM-DD') is missing.

Is there a way that I can accomplish this?

Regards,

The Bird.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You are right, the quotes in String parameter values get stripped.

Do you need to pass the entire phrase? Can you just pass the date?
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Can't you just do WHERE CNSM_END_DT = TO_DATE(\'2999-12-31\',\'YYYY-MM-DD\') ?
thebird
Participant
Posts: 254
Joined: Thu Jan 06, 2005 12:11 am
Location: India
Contact:

Post by thebird »

ArndW wrote:Can't you just do WHERE CNSM_END_DT = TO_DATE(\'2999-12-31\',\'YYYY-MM-DD\') ?
Hi,

Thanks Craig, Arnd for your quick responses... Arnd's solution worked. Thanks a lot.

But can you tell me how the quotes get recognised by giving a "" before it? I dont know about this.

Regards,
The Bird.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

the \' construct tells it not to parse the quote but accept it unparsed. This is commonly used both at UNIX level and also in Oracle SQL.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

It's called 'escaping' and the back-slash is the default escape character. It is usually used to tell something to ignore a metacharacter and (as Arnd notes) accept it 'unparsed'. In this case it also works for quotes.

I didn't mention it because in my experience with the Server product it doesn't help. So... either my memories are faulty, it only actually works in the PX product or... they've managed to fix that. :?

Glad you got it working.
-craig

"You can never have too many knives" -- Logan Nine Fingers
thebird
Participant
Posts: 254
Joined: Thu Jan 06, 2005 12:11 am
Location: India
Contact:

Post by thebird »

Got it Craig,Arnd.

Thanks once again.

Regards,

The Bird.
Post Reply