Sql server MSSQL子查询返回值

Sql server MSSQL子查询返回值,sql-server,Sql Server,如果下面的查询返回的值小于45,我需要一个返回“True”的查询 select sum(assignmentPoints) as Points from Assignment a join Studies s on a.courseCode = s.courseCode and a.assignmentName = s.assignmentName and a.sectionName = s.sectionName and pnr = '851326' where assignmentPoint

如果下面的查询返回的值小于45,我需要一个返回“True”的查询

select sum(assignmentPoints) as Points from Assignment a join Studies s
on a.courseCode = s.courseCode and a.assignmentName = s.assignmentName and a.sectionName = s.sectionName and pnr = '851326'
where assignmentPoints > 45
如果该查询返回的值大于45,我还希望该查询返回'False',换句话说,如果该查询返回'null'

有人能帮我吗

/////编辑


您知道是否可以将该查询转换为函数吗?函数将根据查询返回False或True

/////编辑


阿里先生和汉普蒂·达姆蒂想出了解决办法

您可以创建一个函数。我使用了M.ALi的相同代码

select CASE 
           WHEN  sum(assignmentPoints) > 45 
             THEN 'TRUE'
            ELSE 'FALSE' 
       END as Points 
from Assignment a 
join Studies s  on a.courseCode     = s.courseCode 
               and a.assignmentName = s.assignmentName 
               and a.sectionName    = s.sectionName 
               and pnr              = '851326'

您知道是否可以将该查询转换为函数吗?函数将返回False或True而不是查询。由于某种原因,我删除了“as Points”,这使得assignmentPoints列无效。但当我取下它时,它就像一个符咒!这是一个伟大的解决方案!我向你们两位好先生致敬!谢谢阿里先生和汉普蒂·达姆蒂!我会投票,但我不能。@Reality Torrent:当然你不需要这里的别名:)
CREATE FUNCTION fn_FunctionName
(
    -- Add the parameters for the function here
    @PNR VARCHAR(50)
)
RETURNS BIT
AS
BEGIN
    -- Declare the return variable here
    DECLARE @Result BIT =0 

    select @Result = CASE 
               WHEN  sum(assignmentPoints) > 45 
                 THEN 1
                ELSE 0
           END
    from Assignment a 
    join Studies s  on a.courseCode     = s.courseCode 
                   and a.assignmentName = s.assignmentName 
                   and a.sectionName    = s.sectionName 
                   and pnr              = @PNR


    -- Return the result of the function
    RETURN @Result

END
GO