I've tried searching but I'm not entirely sure how to word it so apologies in advance if this has already been answered elsewhere.
I am trying to select Everything between a date range (Including where there is no value for that date) for mutiple values. I havent really explained very weel but below is an example of the ouput I am after.
Date Campaign Channel Transaction
01/01/2015 a Online Sale
01/01/2015 b Online Sale
01/01/2015 c Online Sale
01/01/2015 a Online Cancellation
01/01/2015 b Online Cancellation
01/01/2015 c Online Cancellation
01/01/2015 a Offline Sale
01/01/2015 b Offline Sale
01/01/2015 c Offline Sale
01/01/2015 a Offline Cancellation
01/01/2015 b Offline Cancellation
01/01/2015 c Offline Cancellation
02/01/2015 a Online Sale
02/01/2015 b Online Sale
02/01/2015 c Online Sale
02/01/2015 a Online Cancellation
02/01/2015 b Online Cancellation
02/01/2015 c Online Cancellation
02/01/2015 a Offline Sale
02/01/2015 b Offline Sale
02/01/2015 c Offline Sale
02/01/2015 a Offline Cancellation
02/01/2015 b Offline Cancellation
02/01/2015 c Offline Cancellation
I am able to select every day between a date range however cannot work out how to select every day with every outcome even if no results are returned.
Edit - Added solution I found
OK, So I have a solution which seems to be working for me. There may be a better way of doing this and any suggestions are appreciated but here is what I am now doing
Declare @CC TABLE (Campaign varchar(50))
DECLARE @Channel Table (Channel Varchar(255))
DECLARE @TYPE TABLE (Transaction_Type varchar(255))
Insert Into @CC (Campaign) Values ('1')
Insert Into @CC (Campaign) Values ('2')
Insert Into @Channel (Channel) Values ('Online')
Insert Into @Channel (Channel) Values ('Inbound')
Insert Into @TYPE (Transaction_Type) Values ('Sale')
Insert Into @TYPE (Transaction_Type) Values ('Cancellation')
DECLARE
@StartDate DATE = Dateadd(YY,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)),
@EndDate DATE = Getdate()
SELECT
DATEADD(DAY, nbr - 1, @StartDate) as Dates,
Campaign,
Channel,
Transaction_Type
FROM ( SELECT ROW_NUMBER() OVER ( ORDER BY c.object_id ) AS Nbr
FROM sys.columns c) nbrs,
@CC, @Channel, @TYPE WHERE nbr - 1 <= DATEDIFF(DAY, @StartDate, @EndDate)
Order by Dates asc, Campaign asc, Channel asc, Transaction_Type asc