on-internet
← Community

How do I ensure a select statement returns null values for specific columns?

Stack Overflow ·

I have a query that joins two tables. I'm using an IF statement that dictates what to return. One path runs the query/join as is, the other needs to return all of the data from the first column, but only return column names with null values. Here's the query I have now for that: declare @Date DATE = '06/07/2012' IF @DATE >= GETDATE() BEGIN SELECT DisplayName, '' [RegularHours], ''[OvertimeHours] FROM Sites ORDER BY DisplayName END ELSE SELECT sites.DisplayName, hrs.SiteDate, hrs.RegularHrs, hrs.OverTimeHrs FROM Sites sites left join SiteHours hrs on sites.SiteID = hrs.SiteID ORDER BY DisplayNa

Comments

Sign in or sign up to comment and upvote.

No comments yet.