I haven't work with DB2, so if you're trying to write a text file directly from
the Database, you should look at the native DB2 utility.
However, you you read this into a recordset then it will be fairly simple
1. Check if recordset isn't empty
2. Loop through the recordset with the While or Do commands and for each record
write the data to the text file.
I assume you know how to do this. If not write me another email and I will give
you the syntax.
>
> I have a need to run a sql statement against DB2 and based on the results of
that query write the output to a TXT file.
>
> SQL Looks like this.
>
> =============-----------------===================------------------
>
> SELECT
> SAPDW.DW_CALENDAR.sales_cur_date,
> SAPDW.DW_BILLTO.BILLTO_NBR,
> SAPDW.DW_BILLTO.BILLTO_NAME,
> SAPDW.DW_BILLTO.BILLTO_COUNTRY_DESC,
> SAPDW.DW_BILLTO.BILLTO_SALES_CHANNEL_CODE,
> SAPDW.DW_BILLTO.SUB_CHANNEL_CODE,
> SAPDW.DW_COMPANY.COMPANY_CODE || ' - ' || SAPDW.DW_COMPANY.COMPANY_DESC
> FROM
> SAPDW.DW_CALENDAR,
> SAPDW.DW_BILLTO,
> SAPDW.DW_COMPANY,
> SAPDW.DW_LINE_TYPE,
> SAPDW.DW_SALES,
> SAPDW.DW_CURRENCY_RATE CURRENCY_RATE_BUS_DAYS
> WHERE
> ( SAPDW.DW_SALES.LINE_TYPE_SK=SAPDW.DW_LINE_TYPE.LINE_TYPE_SK )
> AND ( SAPDW.DW_CALENDAR.DATE_KEY=SAPDW.DW_SALES.GL_DATE_SK )
> AND ( SAPDW.DW_SALES.BILLTO_SK=SAPDW.DW_BILLTO.BILLTO_SK )
> AND ( SAPDW.DW_BILLTO.BILLTO_RECORD = 'Y' )
> AND ( SAPDW.DW_COMPANY.COMPANY_SK=SAPDW.DW_SALES.COMPANY_SK )
> AND ( CURRENCY_RATE_BUS_DAYS.CURRENCY_TYPE='EURXYTD' AND
SAPDW.DW_SALES.COMPANY_CURRENCY=CURRENCY_RATE_BUS_DAYS.CURRENCY_FROM
> )
> AND ( SAPDW.DW_CALENDAR.SALES_CUR_YEAR=CURRENCY_RATE_BUS_DAYS.FISCAL_YR )
> AND ( SAPDW.DW_CALENDAR.SALES_CUR_MONTH=CURRENCY_RATE_BUS_DAYS.MONTH_NBR )
> AND
> (
> SAPDW.DW_BILLTO.BILLTO_NBR <> 0
> AND
> SAPDW.DW_BILLTO.SUB_CHANNEL_CODE In ( '10','20','30' )
> AND
> SAPDW.DW_BILLTO.CUSTOMER_GROUP5_CODE = ' '
> AND
> SAPDW.DW_COMPANY.COMPANY_CODE = 'OPTR'
> AND
> SAPDW.DW_LINE_TYPE.LINE_TYPE_CODE In ( 'GR','ZR','DR','CD','AR' )
> )
>
> =============-----------------===================------------------
>
> How would I go about writing the results to a text file?
>