Datastage routine for running SQL

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
chandu123
Premium Member
Premium Member
Posts: 40
Joined: Mon Sep 12, 2016 1:26 pm

Datastage routine for running SQL

Post by chandu123 »

I have created a datastage server routine to run SQLs by taking the below post as a reference:

viewtopic.php?p=351611

My routine is:

Code: Select all

*Write query to a temporary sql file. 
 cmd= "echo SELECT TO_CHAR(TO_DATE('201608','YYYYMM'),'MON-YY') FROM DUAL; > G:\temp\Datastage\Query.sql"
Call DSExecute("NT",cmd,Output,Retval) 

*execute the sql file 
cmd="sqlplus -s TEST1/test2@DSN< G:\temp\Datastage\Query.sql" 
Call DSExecute("NT",cmd,Output,Returnval) 

Ans=Output
The problem which I am facing is that the quotes in the sql are being removed while writing to the file Query.sql.

Expected: SELECT TO_CHAR(TO_DATE('201608','YYYYMM'),'MON-YY') FROM DUAL;

Actual: SELECT TO_CHAR(TO_DATE(201608,YYYYMM),MON-YY) FROM DUAL;

I tried by wrapping the quotes with double quotes and backslash etc. It didn't work. Please help with any suggestions to get the same SQL written as it is.
HB
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Try putting each single quote inside a pair of single quotes, i.e. each one becomes three.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I'm hoping your SQL example is just a test as you certainly don't need SQL or a database to get that string into MON-YY format. :wink:
-craig

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