TSQL转换查询返回TRUE / FALSE

时间:2017-03-16 04:46:11

标签: tsql sql-server-2012

如何将此查询转换为返回TRUE / FALSE值?

SELECT UserID, ResumeID AS PreviouslyViewed FROM MVJ_ProfileViews
WHERE UserID = [User:UserID]
AND ResumeID = [TknParams:ResumeID]

2 个答案:

答案 0 :(得分:3)

您可以投射结果

SELECT CASE WHEN EXISTS (
    SELECT UserID, ResumeID AS PreviouslyViewed
    FROM MVJ_ProfileViews
    WHERE UserID = [User:UserID] AND
          ResumeID = [TknParams:ResumeID]
)
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT)
END AS result

答案 1 :(得分:0)

IF EXISTS ( SELECT UserID, ResumeID AS PreviouslyViewed
    FROM MVJ_ProfileViews
    WHERE UserID = [User:UserID] AND
          ResumeID = [TknParams:ResumeID])
BEGIN
     SELECT 'TRUE' Result
END
ELSE
BEGIN
     SELECT 'FALSE' Result
END