On Oct 22, 4:48 pm, [EMAIL PROTECTED] (Jeff Pang) wrote: > On 10/22/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > > > Hi forum!!! > > > I am assigning a variable dynamically and using it in a query to > > fetch values from my database. Here is the pseudo code... > > > ########### > > my $string ; > > my $q1 = "select * from bugs where target_milestone = ? and date > > between ? and ?; > > my $q2 = "select * from bugs where $string and target_milestone = ? > > and date between ? and ?; > > > foreach my $q ($q1,$q2){ > > $stmt = $dbh->prepare($q1) or die ""; #####$dbh already has a valid > > handle > > $stmt->execute() or die ""; > > > $string = "bug_id not in (1,2,3)"; #### 1,2,3 are eg. values which > > i get after process $q1 and i #use it in $q2 > > } > > > ################################## > > Farily I don't understand for what you said from the codes above. > You don't need a for loop here,because your logic is not a loop-logic. > Replace the for loop with below, > > # query for $q1 > my $q1 = "select * from bugs where target_milestone = ? and date > between ? and ?"; > my $stmt = $dbh->prepare($q1) or die $dbh->errstr; > $stmt->execute($v1,$v2,$v3) or die $dbh->errstr; # v1,v2,v3 is > needed,they are the query conditions > my @result = $stmt->fetchrow_array; > $stmt->finish; > > #create the string and query for $q2 > my $string = "bug_id not in (" . join ',' , @result . ")"; > my $q2 = "select * from bugs where $string and target_milestone = ? > and date between ? and ?"; > $stmt = $dbh->prepare($q2) or die $dbh->errstr; > $stmt->execute($v1,$v2,$v3) or die $dbh->errstr; > $stmt->finish; > > Dont test it but I think it mostly will work fine. > Good luck!
Thanks .. I have done the same thing. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/