문제

I'm trying to return true or false based on a CASE WHEN THEN tsql statement, but the only thing that ever shows up in the results panel is the column name "IsGeneric".

Where am I going wrong?

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;
도움이 되었습니까?

해결책

You are using apostrophes around the identifier, which makes it a string instead.

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;

다른 팁

SELECT CASE WHEN p.[GenericCatalogID] > 0 
            THEN CAST(1 AS BIT) 
            ELSE CAST(0 AS BIT) 
       END as IsGeneric
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top