consider a query that looks something like this:
my $query=<<QUERY;
select * from foo1 where col < ?
union all
select * from foo2 where col < ?
QUERY
Assume that the actual query really needs unions and can't be efficiently solved another way. The variable in the where clause will always be the same. Is there any way I can structure this so that I only need to pass 1 argument to execute instead of passing the same argument twice?
Could try the following, I'm assuming you're passing an integer to the where clause...
DECLARE @variableName as int
SET @variableName = ? --the value gets passed here once
select * from foo1 where col < @variableName -- and gets used here
union all
select * from foo2 where col < @variableName -- and here!
You could use the list repetition operator.
$sth->execute(($value) x 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With