How to return true or false from tsql using the case where

I am trying to return true or false based on the CASE WHEN THEN tsql statement, but the only thing that ever appears in the results pane is the IsGeneric column name.

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; 
+6
source share
2 answers

You use 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; 
+12
source
 SELECT CASE WHEN p.[GenericCatalogID] > 0 THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END as IsGeneric 
+2
source

Source: https://habr.com/ru/post/956745/


All Articles