SQL query having CASE WHEN EXISTS statement
19:05 22 Oct 2019

I trying to create a SQL query with a CASE WHEN EXISTS clause in SQL Server. I assume I am doing something wrong as when I run the SELECT * FROM [Christmas_Sale] it takes forever for SQL to load the code.

CREATE VIEW [Christmas_Sale]
AS
   SELECT  
       C.*,
       CASE 
          WHEN EXISTS (SELECT S.Sale_Date
                       FROM [Christmas_Sale] s
                       WHERE C.ID = S.ID) 
              THEN 0 
              ELSE 1 
       END AS ChristmasSale
   FROM 
       [Customer_Detail] C ;

I'm trying to write a sub select which I need to return a 1 if Sale_Date= 1 and 0 for anything else.

sql sql-server