Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Re: [TheStone] Using advanced WHERE SQL statement?

Quote Reply
Re: [TheStone] Using advanced WHERE SQL statement? In reply to
Ok... ok.. i see where you are going with this. It should work great. But I get an error when I create this statement.
Code:

Can't call method "fetchall_hashref" on an undefined value at (eval 20) line 21.

Which i know is just a general error because of an empty set or error further up the line. I did some back tracking and it all works except for this statement here:
Code:

GT::SQL::Condition->new('Carriers' => 'NOT IN' => \@ids )

This is the error that I get back from the SQL server:
Code:

GT::SQL::error = Failed to execute query: 'SELECT * FROM Select_Entries WHERE ( Carriers NOT IN ? ) '
Reason: [unixODBC][Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '@P1'. (SQL-42000)

It looks as if the script is passing the array item as SQL code to the server. Am I correct?? How do I get it to print out the exact values and not the array reference to the SQL server?

Maybe I'm on the wrong track here?

For reference, here is the code I'm using right now to get this output:
Code:

my $tags = shift;


# Ok.. create a condition to narrow the patient records.
my $cond = GT::SQL::Condition->new(
'PatientID', '=', $tags->{PatientID},
'Type', '=', $tags->{Type}
);

# Now select the above condition, returning only carrier names.
my $list = $DB->table("Insured")->select('Carrier', $cond)->fetchall_arrayref;
my @ids = map $_->[0], @$list;

# Now only select the records from "Select_Entries" that are NOT matching in Insured table (above).
my $results = $DB->table('Select_Entries')->select(GT::SQL::Condition->new('Carriers' => 'NOT IN' => \@ids))->fetchall_hashref;


# For debugging
use Data::Dumper;
print "<pre>".Dumper($results)."</pre>";
Subject Author Views Date
Thread Using advanced WHERE SQL statement? LanceWilson2 3887 Feb 14, 2005, 12:29 AM
Thread Re: [LanceWilson2] Using advanced WHERE SQL statement?
604 3725 Feb 14, 2005, 1:48 PM
Thread Re: [TheStone] Using advanced WHERE SQL statement?
LanceWilson2 3713 Feb 20, 2005, 9:16 PM
Post Re: [LanceWilson2] Using advanced WHERE SQL statement?
LanceWilson2 3693 Mar 2, 2005, 10:19 AM