Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. DECLARE @StartDate datetime = '6/1/2015',
  2. @EndDate datetime = '6/30/2015'
  3.  
  4. DECLARE @DayRange int = (select DateDiff(day,@StartDate,@EndDate))
  5.  
  6. --This can be done differently, I made this negative
  7. SET @DayRange = - @DayRange
  8.  
  9. --This is your temp table that will have all your dates in the range
  10. DECLARE @Temp Table
  11. (
  12. ID int IDENTITY(1,1),
  13. DataDate DateTime,
  14. DataValue int
  15. )
  16.  
  17. --Fill the temp table with all the dates
  18. WHILE(@DayRange < 1)
  19. BEGIN
  20. INSERT INTO @Temp
  21. SELECT DateAdd(day,@DayRange,@EndDate),0
  22. SET @DayRange = @DayRange + 1
  23. END
  24.  
  25. --Check out your temp table
  26. SELECT * FROM @Temp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement