9

我试图根据 CASE WHEN THEN tsql 语句返回真或假,但结果面板中唯一出现的是列名“IsGeneric”。

我哪里错了?

alter proc Storefront.proc_IsProjectGeneric

@ProjectID INT
AS
SET NOCOUNT ON;

SELECT 'IsGeneric'=CASE WHEN p.[GenericCatalogID] > 0 THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END
                 FROM Storefront.Project p WITH(NOLOCK)
                 WHERE p.ID = @ProjectID;

SET NOCOUNT OFF;
4

2 回答 2

21

您在标识符周围使用撇号,这使它成为一个字符串。

SELECT IsGeneric = CASE WHEN p.[GenericCatalogID] > 0 THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END
             FROM Storefront.Project p WITH(NOLOCK)
             WHERE p.ID = @ProjectID;
于 2013-10-25T19:33:37.610 回答
9
SELECT CASE WHEN p.[GenericCatalogID] > 0 
            THEN CAST(1 AS BIT) 
            ELSE CAST(0 AS BIT) 
       END as IsGeneric
于 2013-10-25T19:31:35.187 回答