Skip to Content.
Sympa Menu

freetds - RE: problem with fetching NULL values

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: donw AT canyoncreek.com (Don Wennick)
  • To: freetds AT franklin.oit.unc.edu
  • Subject: RE: problem with fetching NULL values
  • Date: Tue, 22 May 2001 08:15:32 -0700


Why not just use SQL Server's built in function COALESCE()? Like:

SELECT COALESCE(COL1, COL2) Column FROM myTable

For any list of columns and/or constants, coalesce() returns the
leftmost non-null value.

-----Original Message-----
From: cedric [mailto:cedric AT eolas.fr]
Sent: Tuesday, May 22, 2001 7:52 AM
To: freetds
Cc: cedric
Subject: [freetds] problem with fetching NULL values




Hi,

In my database I've got a table like this

COL1 | COL2
<null> | item 1
abab | item 2
<null> | item 3

I'am using PHP 4.0.4 and freetds and I want to do a test like this :
"if COL1 is null then echo COL2 else echo COL1"

so my code is
----------------------------------
$sql = "COL1, COL2 from myTable";
$rs = mssql_query($sql) or die ("Erreur : $sql<BR>");
$row = mssql_fetch_array($rs);

if (is_null($row[COL1]) || ($row[COL1] == "") || !isset($row[COL1]) ||
($row[COL1] == NULL)) {
// case 1
echo $row[COL2];
} else {
// case 2
echo $row[COL1];
}
--------------------------------------

unfortunatly it always comes in case 2 and echo nothing.

Please help !!

thanks

PS : I tested a code like this and it doesn't worked too (it always echo
XX)

---------------------------
$temp = "X" . $row[COL1] . "X";
if ($temp == "XX") {
echo "something";
} else {
echo $temp;
}
---
You are currently subscribed to freetds as: [donw AT canyoncreek.com]
To unsubscribe, forward this message to
$subst('Email.Unsub')








Archive powered by MHonArc 2.6.24.

Top of Page