日期:2014-05-18  浏览次数:20718 次

子查询里加判断`应该怎么加`我提示IF附近有错``
请问一下   字查询里加判断某列是否为空   应该怎么弄`我老是提示if周围有语法错误
select   Windows.WindowsUserID,Windows.UserID,
(if   Windows.UserID   is   null
(select   DaoQiShiJian   from   Hao   where   Hao.WindowsUserID=Windows.WindowsUserID)
else
                (select   ' ')
)   as   daoqishijian  
from   Windows

要Windows.UserID为空才执行查`否则此列为空字符传``

------解决方案--------------------
select Windows.WindowsUserID,Windows.UserID,
(case when Windows.UserID is null then (select DaoQiShiJian from Hao where Hao.WindowsUserID=Windows.WindowsUserID) else ' ' end case) as daoqishijian
from Windows

在查询语句中不能用IF判断,得用CASE语句。

上面少写了一个then,这次就对了。