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

如何在结果集中查询记录?谢谢!
想在以下结果集中查询PrjectFullName   like   '%test% '的记录,应该怎么写?
结果集如下,能正常执行,
SELECT     (CASE   A.ProjectInputType   WHEN   0   THEN   (CASE   B.ParentID   WHEN   0   THEN   B.ProjectName   ELSE   D.ProjectName+ '_ '+B.ProjectName   END)   ELSE   A.RelationProject   END)as   PrjectFullName
FROM   RFMItems   A,RFMProject   B     LEFT   OUTER   JOIN
RFMProject   D   ON   B.ParentID   =   D.RFMProjectID
WHERE     (charindex(   ', '+rtrim(B.RFMProjectID)+ ', '   ,   ', '+rtrim(A.RelationProject)+ ', '   )   >   0
AND   A.ProjectInputType=0  
)  
想实现的功能如下,不确报错,报错内容为: "第   16   行:   ') '   附近有语法错误。 "
SELECT   *
FROM   (

SELECT     (CASE   A.ProjectInputType   WHEN   0   THEN   (CASE   B.ParentID   WHEN   0   THEN   B.ProjectName   ELSE   D.ProjectName+ '_ '+B.ProjectName   END)   ELSE   A.RelationProject   END)as   PrjectFullName
FROM   RFMItems   A,RFMProject   B     LEFT   OUTER   JOIN
RFMProject   D   ON   B.ParentID   =   D.RFMProjectID
WHERE     (charindex(   ', '+rtrim(B.RFMProjectID)+ ', '   ,   ', '+rtrim(A.RelationProject)+ ', '   )   >   0
AND   A.ProjectInputType=0  
)  

)
我确定括号已经匹配,
在最后加上 "; "也报错.
哪位知道的话请帮忙看看!谢谢!



------解决方案--------------------
SELECT *
FROM (

SELECT (CASE A.ProjectInputType WHEN 0 THEN (CASE B.ParentID WHEN 0 THEN B.ProjectName ELSE D.ProjectName+ '_ '+B.ProjectName END) ELSE A.RelationProject END)as PrjectFullName
FROM RFMItems A,RFMProject B LEFT OUTER JOIN
RFMProject D ON B.ParentID = D.RFMProjectID
WHERE (charindex( ', '+rtrim(B.RFMProjectID)+ ', ' , ', '+rtrim(A.RelationProject)+ ', ' ) > 0
AND A.ProjectInputType=0
)

) A --加上個別名即可