Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datastage: job parameter read from table in database

Status
Not open for further replies.

XianII

IS-IT--Management
Mar 13, 2002
1
ES
Hi, I'm trying to read a date from one table and use that date as a parameter on another job. How can I do that?

I've trying with batch jobs, but i don't know how to launch a sql query from code.

Thanks in advance.
Xian
 
Here's the code:

Funcion: ExecSQL(OraHost, OraUser, OraPassword, SQL)
Note: Although built for Oracle, works with ANY ODBC Data Source.

**********************************************************
#include DSINCLUDE ODBC.H

Common /execsql/ result, rowcount, info

rowlimit = 0
fcname = "ExecSQL"
result = ""

err = SQLAllocEnv(env1)

if err <> SQL.SUCCESS then
Call DSLogFatal(&quot;Erro na alocação de ENVIRONMENT.&quot;, fcname)
return(-1)

end

err = SQLAllocConnect(env1, conn1)

if err <> SQL.SUCCESS then
status = SQLFreeEnv(env1)
Call DSLogFatal(&quot;Erro na alocação de CONNECTION.&quot;, fcname)
return(-1)

end

err = SQLConnect(conn1, OraHost, OraUser, OraPassword)

if err <> SQL.SUCCESS then
status = SQLFreeConnect(conn1)
status = SQLFreeEnv(env1)
Call DSLogFatal(&quot;Erro na conexão com &quot;:OraHost, fcname)
return(-1)

end

err = SQLAllocStmt(conn1, stmt1)

if err <> SQL.SUCCESS then
status = SQLDisconnect(conn1)
status = SQLFreeConnect(conn1)
status = SQLFreeEnv(env1)
Call DSLogFatal(&quot;Erro na alocação do comando '&quot;:SQL:&quot;' em &quot;:OraHost, fcname)
return(-1)

end

err = SQLExecDirect(stmt1, SQL)
status = SQLError(env1, conn1, stmt1, sqlstate, dbmscode, errmsg)
info = &quot;SQL State: &quot;:sqlstate:mad:FM:&quot;DBMS Code: &quot;:dbmscode:mad:FM:errmsg

if err <> SQL.SUCCESS then
status = SQLFreeStmt(stmt1, SQL.DROP)
status = SQLDisconnect(conn1)
status = SQLFreeConnect(conn1)
status = SQLFreeEnv(env1)
Call DSLogFatal(&quot;Erro na execução do comando [&quot;:SQL:&quot;] em &quot;:OraHost:&quot;:&quot;:mad:FM:info, fcname)
return(-1)

end

err = SQLNumResultCols(stmt1, numcols)

if err <> SQL.SUCCESS then
status = SQLFreeStmt(stmt1, SQL.DROP)
status = SQLDisconnect(conn1)
status = SQLFreeConnect(conn1)
status = SQLFreeEnv(env1)
Call DSLogFatal(&quot;Erro na execução do comando [&quot;:SQL:&quot;] em &quot;:OraHost:&quot;, comando SQLNumResultCols&quot;, fcname)
return(-1)

end

err = SQLRowCount(stmt1, rowcount)

if err <> SQL.SUCCESS then
status = SQLFreeStmt(stmt1, SQL.DROP)
status = SQLDisconnect(conn1)
status = SQLFreeConnect(conn1)
status = SQLFreeEnv(env1)
Call DSLogFatal(&quot;Erro na execução do comando [&quot;:SQL:&quot;] em &quot;:OraHost:&quot;, comando SQLRowCount&quot;, fcname)
return(-1)

end

if rowcount < 0 then rowcount = 0

if numcols = 0 then
status = SQLFreeStmt(stmt1, SQL.DROP)
status = SQLDisconnect(conn1)
status = SQLFreeConnect(conn1)
status = SQLFreeEnv(env1)
return(SQL.SUCCESS)

end

dimension line(numcols)

for i = 1 to numcols
status = SQLBindCol(stmt1, i, SQL.B.DEFAULT, line(i))

next

rownum = 0

loop while @True
err = SQLFetch(stmt1)

if err = 100 then exit

if err <> SQL.SUCCESS then
err = SQLError(env1, conn1, stmt1, sqlstate, dbmscode, errmsg)
status = SQLFreeStmt(stmt1, SQL.DROP)
status = SQLDisconnect(conn1)
status = SQLFreeConnect(conn1)
status = SQLFreeEnv(env1)
Call DSLogFatal(&quot;Erro na execução do comando [&quot;:SQL:&quot;] em &quot;:OraHost:&quot;, comando SQLFetch:&quot;:mad:FM:&quot;SQL State: &quot;:sqlstate:mad:FM:&quot;DBMS Code: &quot;:dbmscode:mad:FM:errmsg, fcname)
return(-1)

end

if result <> &quot;&quot; then result = result:mad:FM

for i = 1 to numcols
result = result:line(i)
if i < numcols then result = result:&quot;,&quot;

next

rownum += 1
if rownum > rowlimit and rowlimit > 0 then exit

repeat

Ans = SQL.SUCCESS

status = SQLFreeStmt(stmt1, SQL.DROP)
status = SQLDisconnect(conn1)
status = SQLFreeConnect(conn1)
status = SQLFreeEnv(env1)
**********************************************************

Cheers,
Deny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top