JQGRID中的SQL语句在SQL中返回值时返回null

时间:2015-11-02 14:40:47

标签: jquery sql jqgrid ibm-midrange

以下代码在第二列(STSEL)中返回null。当我独立运行SQL语句时,它会按预期返回“Y”或“N”。

我不明白为什么会这样做。非常感谢任何帮助。

注意:我直接回应了$ response的结果,它显示为null,因此它不是导致这种情况的网格配置。

$where = "a.VER = (SELECT max(e.CVER) FROM prodlib.vercntl e WHERE e.VERDTE <= 20151031) 
      AND a.LVL2 like 'RRG%' AND substr(a.LVL4,1,2) = '00' AND b.TYPE = 'SCT'  
      AND d.ST = '$state' AND d.LSEQ = $seq";

$sql = "SELECT LROWID, STSEL, ST, STORE, STNAME, CLSEQ, LVL4
      FROM 
      ( SELECT row_number() OVER ( ORDER BY 1 asc ) AS rid, d.LROWID, (CASE WHEN (d.ST is not null) THEN 'Y' ELSE 'N' END) as STSEL, c.ST, a.STOR, a.NAME, c.CLSEQ, a.LVL4
          FROM prodlib.smpmt a
            LEFT OUTER JOIN prodlib.dmpcv b ON a.ST = substr(b.FD1,1,2)
            LEFT OUTER JOIN devlib.pyp280c@ c ON a.st = c.ST
            LEFT OUTER JOIN devlib.pyp280l@ d ON c.ST=d.ST AND c.CLSEQ=d.LSEQ AND a.STOR = d.STOR
          WHERE $where
      ) AS t
      WHERE (t.rid BETWEEN 1 AND 20) ORDER BY STSEL desc, STORE";

if ($conn) {

$stmt = db2_exec($conn, $sql);

$response = (object) array('page' => $page, 'total' => $total_pages, 'records' =>$rowcount, 'rows' => "");

$response->page = $page;
$response->total = $total_pages;
$response->records = $rowcount;
$i=0;
while ($row = db2_fetch_object($stmt)) {
$response->rows[$i]['id']=trim($row->LROWID);
$response->rows[$i]['cell']=array($row->LROWID, $row->STSEL, $row->ST, $row->STORE, $row->STNAME, $row->CLSEQ, $row->LVL4);
$i++;
} 

echo json_encode($response);

非常感谢和最诚挚的问候。

2 个答案:

答案 0 :(得分:0)

为什么不尝试使用coalesce?

http://www.w3schools.com/sql/sql_isnull.asp

coalesce(d.ST,'N')用N

替换所有空值

答案 1 :(得分:0)

我做了这个并且它有效。我不确定为什么它不能以第一种方式工作。

if (is_null($row->ROWID)) {
    $STSEL = 'N';
}  else  {
    $STSEL = 'Y';
}
$response->rows[$i]['id'] = trim($row->LROWID);
$response->rows[$i]['cell'] = array($row->LROWID, $STSEL, $row->ST, $row->STORE, $row->STNAME, $row->CLSEQ, $row->LVL4);
$i++;