in reply to Array, SQL Question!

First, your @array_num variable is getting populated with a single value the way that your code is written. Try this:

my @array_num = qw/123 456 345 459 234/;

Second, you never set $n1 and $n2 to anything. I'll assume that you want them to be the first and second values in your array.

my $n1 = $array_num[0]; my $n2 = $array_num[1];

Third, you really should be using placeholders (or bind parameters) in your $sql statement to safeguard against SQL injection attacks. This is not much of a problem in the statements as you've presented them, but it's really a good practice to get into. Read more about SQL placeholders.

So, finally, we have this:

my @array_num = qw/123 456 345 459 234/; my $n1 = $array_num[0]; my $n2 = $array_num[1]; my $sql= " SELECT tb.num1, tb.num2 FROM MYTABLE tb WHERE tb.num1 = ? AND tb.num2 = ?"; $sql->execute($n1, $n2);

EDIT: Per trammell's reply below.

Replies are listed 'Best First'.
Re^2: Array, SQL Question!
by trammell (Priest) on Nov 11, 2004 at 21:05 UTC
    I think you want e.g.:
    my $n1 = $array_num[0]; my $n2 = $array_num[1];
Re^2: Array, SQL Question!
by Anonymous Monk on Nov 11, 2004 at 20:37 UTC
    I dont want the value of $n2 to be part of the array just values from $n1

      Your original node didn't state what $n1 or $n2 were supposed to be. Multiple respondents (myself included) assumed that you made a mistake in the assignment of your @array_num variable. Furthermore, I stated that I was making an assumption about what you wanted in $n1 and $n2.

      I've re-read your original post as well as your reply to mine, and I still don't know what you want for $n1 and $n2. I'm going to now assume that you know what they are, as well as how to populate them, unless you give more specific information about what you want in them.

        You could also add that if the OP is actually wanting to store "123,456,789..." in a single field they are breaking one of the most basic of all database design rules.

        cheers

        tachyon