Ram*_*mie 4 sql sql-server-2008
在查询运行时,如何在select语句中实现布尔逻辑?
SELECT t.[Key]
      ,t.[Parent_Key]
      ,t.[Parent_Code]
      ,t.[Code]
      ,t.[Desc] 
      ,t.[Point]
      ,[isChild] -- If Point > 2, then true, if Point == 1 Then false   
      ,t.[By] 
      ,t.[On]
FROM [db].[stats] t WHERE t.[Parent_Key]= @tmpParameter
我想根据t确定[isChild]布尔值的一些逻辑.[点]
SELECT t.[Key]
      ,t.[Parent_Key]
      ,t.[Parent_Code]
      ,t.[Code]
      ,t.[Desc] 
      ,t.[Point]
      ,CASE WHEN t.[Point] > 2 THEN 1 ELSE  
            CASE WHEN t.[Point] = 1 THEN 0 ELSE NULL END 
       END AS [isChild]
      ,t.[By] 
      ,t.[On]
FROM [db].[stats] t WHERE t.[Parent_Key]= @tmpParameter
请注意,当t.[Point] <1时,[isChild]将为null
| 归档时间: | 
 | 
| 查看次数: | 719 次 | 
| 最近记录: |