On 4/18/07, Katie L. Barbee <[EMAIL PROTECTED]> wrote:
I believe this is a very simple question or at least I'm hoping ...
I am trying to select items from a table where the miles field is not
null or blank and the below statement does not work. Does anyone have
any suggestions?
Thanks!
@resultkeys = ("Date","People","Miles","Savings");
$sql = "SELECT c.objectid,c.dateadded as
\"Date\",c.totalpeople as \"People\", ";
$sql .= "c.miles as Miles, c.totalsaved as \"Savings\" ";
$sql .= "FROM OWNER.CONFERENCE c";
$sql .= " WHERE c.miles <> "";
$sql .= " ORDER BY c.datestart";
Well, part of your problem is that c.datestart is not in your query,
so you can't sort on it. You can use the "is null" comparison (I
believe it is the same in all flavours of SQL) to test for null, I
don't know what flavor of SQL you are using, so I don't know if empty
string is '' or "", but I have preserved what you did. I hope you are
using the DBI for this. You can get more information by looking at
$dbh->errstr after a failed $sth->execute or $sth->prepare.
my $sql = qq(
SELECT
c.objectid,
c.datestart as "DateStart"
c.dateadded as "Date",
c.totalpeople as "People",
c.miles as "Miles",
c.totalsaved as "Savings"
FROM owner.conference c
WHERE c.miles IS NOT NULL
AND c.miles != ''
ORDER BY c.datestart
);
my $sth = $dbh->prepare($sql) or die $dbh->errstr;
$sth->execute or die $dbh->errstr;
while (my $row = $sth->fetchrow_hashref) {
print "@[EMAIL PROTECTED]";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/