aesalus1976
New User
May 11, 2009, 2:19 AM
Post #1 of 1
(5498 views)

sql statement with no result

Can't Post


Hello everybody. why my script: .... $dbh = DBI>connect("DBI:Pg:dbname=dbname", "user", "passwd"); my $query1 = qq{select x.sum as pocetnost, sum(*) as suma from (select case when sum(*) between 1 and 9 then '01) 19' when sum(*) between 10 and 14 then '02) 1014' when sum(*) between 15 and 19 then '03) 1519' when sum(*) between 20 and 24 then '04) 2024' when sum(*) between 25 and 29 then '05) 2529' when sum(*) between 30 and 34 then '06) 3034' when sum(*) between 35 and 39 then '07) 3539' when sum(*) between 40 and 44 then '08) 4044' when sum(*) between 45 and 49 then '09) 4549' when sum(*) between 50 and 59 then '10) 5059' when sum(*) between 60 and 69 then '11) 6069' when sum(*) between 70 and 79 then '12) 7079' when sum(*) between 80 and 89 then '13) 8089' when sum(*) between 90 and 99 then '14) 9099' when sum(*) between 100 and 124 then '15) 100124' when sum(*) between 125 and 149 then '16) 125149' when sum(*) between 150 and 174 then '17) 150174' when sum(*) between 175 and 199 then '18) 175199' when sum(*) between 200 and 249 then '19) 200249' when sum(*) between 250 and 299 then '20) 250299' when sum(*) between 300 and 499 then '21) 300499' when sum(*) between 500 and 749 then '22) 500749' when sum(*) between 750 and 899 then '23) 750899' when sum(*) between 900 and 4000 then '24) viac ako 900' else '25) nezname stado' end as sum from animal as a, transfer as b where a.db_animal = b.db_animal and b.exit_dt notnull group by a.db_herd order by sum) as x group by x.sum}; my ($pocetnost, $suma); my $sth1 = $dbh>prepare($query1); $sth1>execute; my $row = $sth1>rows; $sth1>bind_col(1, \$pocetnost); $sth1>bind_col(2, \$suma); print "Number of rows: $rows"; while ($sth1>fetchrow_arrayref) { $pocetnost =~ s/....//; print RES "<TR>\n"; print RES "<TD VALIGN=TOP>$pocetnost</TD><TD VALIGN=TOP>$suma</TD>\n</TR>\n"; } print RES "</table></tbody> ....... return zero rows but through psql it works correctly with 25 rows. It is wokrs correctly through both (psql and perl) only if I skip where section and use only table animal. Thank you in advance.
