in reply to Re: Passing an Array of Attributes to SQL
in thread Passing an Array of Attributes to SQL

The perl script works...sql and all in the current format. The case statements are as follows:

,max(CASE WHEN week_end_date = '26-SEP-09' THEN rank END) AS DATE_AS_O +F_09_26_2009 ,max(CASE WHEN week_end_date = '19-SEP-09' THEN rank END) AS DATE_AS_O +F_09_19_2009

They already have a comma in them. Since I am introducing multiple lines, it has to come in with a comma. That part works. I just want to be able to read in more than one part of the array. I want to read the entire array as a string.

Replies are listed 'Best First'.
Re^3: Passing an Array of Attributes to SQL
by mje (Curate) on Oct 07, 2009 at 14:21 UTC

    Are you saying fetchrow_arrayref returns:

    [ [',max(CASE WHEN week_end_date = '26-SEP-09' THEN rank END) AS DATE_A +S_OF_09_26_2009'], [',max(CASE WHEN week_end_date = '19-SEP-09' THEN rank END) AS DATE_A +S_OF_09_19_2009'] ]

    or show us what use Data::Dumper;print Dumper($case); outputs.

      Yes. The array reference returns the two case statements. I did

      use Data::Dumper;print Dumper($case);

      and it returns the two case statements.

      I also printed it and it returns the same thing. I am passing a case statement as an attribute / object and when I passed one to the sql statement perl sends it to sqlplus as a normal part of the query. And it works. I just want to be able to send all of them as one string to the query.

        Assuming fetchrow_arrayref is returning multiple rows but each row has one column which is your case SQL beginning with a comma already then why can't you just do:

        my $case = $case_query1->fetchall_arrayref(); my $casestr = join(q{}, @{$case}); . . . my $case_stmt3 = "create table case_st_data1 as (S +ELECT rd, store_number $casestr FROM test_ptw_bottom_10 where week_end_date in ('19-SEP-09','26-sep-09') group by rd, store_number)";