How to return true or false from tsql using case when

Filling The Stack is What I DO picture Filling The Stack is What I DO · Oct 25, 2013 · Viewed 25.1k times · Source

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;

Answer

Guffa picture Guffa · Oct 25, 2013

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;