Read from DB2 table with multiple SQLs and load into a file

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
via
Premium Member
Premium Member
Posts: 118
Joined: Fri Sep 23, 2005 3:10 pm

Read from DB2 table with multiple SQLs and load into a file

Post by via »

Hi,

I am trying to read from a few DB2 tables by running different (stand-alone) SQLs and send it to a file. In the DB2_UDB_API stage, I am using 'Custom SQL statement' and it appears that only one SQL can be entered here. Please let me know if there is a different approach to achieve this. Thanks in-advance.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Either do a UNION there or use multiple source stages and a Funnel.
-craig

"You can never have too many knives" -- Logan Nine Fingers
via
Premium Member
Premium Member
Posts: 118
Joined: Fri Sep 23, 2005 3:10 pm

Post by via »

Thanks. UNION does not work even in TOAD, as the return values from the SQLs are different numbers (One SQL returns 2 fields, another 5 fields so on). Multiple source stages is an option but since there are many SQLs, I am keeping that as a last option. Not sure if I go for 'Load SQL from File at Run time' will work in this scenario.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Of course a union would require the same number (and type) of output fields between all of the sql statements, that's how it works. Can you pad them out so they all are similar, selecting NULL or "" or 0 for the 'missing' columns?

And no, loading the sql from a file won't make any difference.
-craig

"You can never have too many knives" -- Logan Nine Fingers
via
Premium Member
Premium Member
Posts: 118
Joined: Fri Sep 23, 2005 3:10 pm

Post by via »

Thanks Craig. When I tried 2 SQLs with union (same no and type), following error appears. 'DB2_UDB_API_29: The 2 column(s) defined on this link do not match the 2 column result set generated by the SQL statement:.....".
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Then it would seem your column metadata in the stage don't match what the SQL is delivering. I've done this without issue in Oracle but I have no clue if DB2 adds any 'special restrictions' to this process.
-craig

"You can never have too many knives" -- Logan Nine Fingers
via
Premium Member
Premium Member
Posts: 118
Joined: Fri Sep 23, 2005 3:10 pm

Post by via »

OK, when I tested with 2 SQLs, I defined 2 O/P Columns, but should have been one column only as my SELECT query returns only one column but 2 rows. So, that is resolved now. But still, for mixed no of result sets (multiple SQLs), I need to figure out a design.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

For that you will need multiple source stages and some way to homogenize the data before you funnel it all together... unless your file struture will support multiple record types.
-craig

"You can never have too many knives" -- Logan Nine Fingers
via
Premium Member
Premium Member
Posts: 118
Joined: Fri Sep 23, 2005 3:10 pm

Post by via »

Yes, that is what I am doing. Happy New Year. Thanks.
Post Reply