2017-03-16 89 views
1

如何轉換此查詢以返回TRUE/FALSE值?TSQL轉換查詢返回TRUE/FALSE

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

您當前的查詢將返回用戶的ID和繼續ID。這對TRUE/FALSE有什麼關係? –

+0

我試圖確定'UserID = 1'是否查看過'ResumeID = 1',然後返回'true',否則'false' – UserSN

回答

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 
+0

完美謝謝! – UserSN

+0

它幫助你我的榮幸。 –

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