SQL Server WHERE Clause using Temporary Columns

Posted by AbeP on Stack Overflow See other posts from Stack Overflow or by AbeP
Published on 2009-12-12T02:36:59Z Indexed on 2010/03/12 18:27 UTC
Read the original article Hit count: 246

Filed under:
|
|
|

Hi all,

I have the following query, which uses a CASE statement. Is there anyway to add into the where clause WHERE IsBusinessDayFinal = 0? without using a temporary table?

thanks so much!

SELECT 
    	ac.DateTimeValue,
    	CASE 
    		WHEN pc.IsBusinessDay IS NOT NULL THEN pc.IsBusinessDay
    		ELSE ac.IsBusinessDay
    	END AS IsBusinessDayFinal,
    	ac.FullYear,
    	ac.MonthValue,
    	ac.DayOfMonth,
    	ac.DayOfWeek,
    	ac.Week	
    FROM 
    	[dbo].[AdminCalendar] ac LEFT JOIN
    	[dbo].ProjectCalendar pc ON ac.DateTimeValue = pc.DateTimeValue AND pc.ProjectId = @projectId
    WHERE ac.DateTimeValue >= @startDate AND ac.DateTimeValue <= @finishDate;

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql