Wednesday, July 2, 2014

T-SQL: Get a list of dates

Returns a list of dates from first of year to end of year
DECLARE @startofyear DATETIME, @endofyear DATETIME
SET @startofyear =   DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)
SET @endofyear = DATEADD(yy, DATEDIFF(yy,0,getdate()) + 1, -1);

WITH sample AS (
  SELECT @startofyear  AS [Date]  
  UNION ALL
  SELECT DATEADD(dd, 1, [Date])
    FROM sample s
   WHERE DATEADD(dd, 1, [Date]) <=  @endofyear) 
SELECT * 
  FROM sample
  option (maxrecursion 370) –loop not more than 370, change to zero to infinite



15 comments:

  1. Packers And Movers Bangalore Local Household Shifting Service, Get Free Best Price Quotes Local Packers and Movers in Bangalore List , Compare Charges, Save Money And Time @ Packers And Movers in Bangalore

    ReplyDelete
    Replies
    1. Great Article Cyber Security Projects projects for cse Networking Security Projects JavaScript Training in Chennai JavaScript Training in Chennai The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  2. Packers and Movers Hyderabad Give Certified and Verified Service Providers, Cheap and Best ###Office Relocation Charges, ***Home Shifting, ???Goods Insurance worth Rs. 10,000, Assurance for Local and Domestic House Shifting. Safe and Reliable Household Shifting Services in Hyderabad with Reasonable Packers and Movers Price Quotation @
    Packers And Movers Hyderabad

    ReplyDelete
  3. Local Packers and Movers Bangalore List, Get Best Price Quotes, Compare Movers and packers Charges, Top, Local Household Shifting Services
    Packers And Movers Bangalore

    ReplyDelete
  4. Packers and Movers Bangalore as a Services providing company can make all the difference to your ###Home Relocation experience. Bangalore based Company which offers versatile solutions, Right team that easily reduce the stress associated with a ✔✔✔Household Shifting, ***Vehicle Transportation. we help things run smoothly and reduce breakages and offer you seamless, Affordable, Reliable Shifting Services, Compare Shifting Charges @ Packers And Movers Bangalore

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. The Most Reliable Packers And Movers Bangalore And Trusted Partners For All Your Packing,
    Shifting And Relocation Services: Packers and Movers Shifting Services in Bangalore helps you relocate to and from Bangalore,
    within city, Interstate, domestic and International destinations. Absolutely stress and Hassle-free Shifting Services in Bangalore.
    As part of our services, we also offer a host of other complimentary relocation services designed to meet both individuals specific
    moving and relocating needs and companys corporate relocation objectives. We are the best local option for Shifting, domestic Shifting, Household packing, Commercial movement, Vehicle transportation in Bangalore and all that you wish to relocate. @ Packers And Movers Bangalore

    ReplyDelete
  7. Get Shifting/Relocation Quotation from ###Packers and Movers Delhi. Packers and Movers Delhi 100% Affordable and Reliable ***Household Shifting Services. Compare Transportation Charges and Save Time, Verified and Trusted Packers and Movers in Delhi, Cheap and Safe Local, Domestic House Shifting @
    Packers And Movers Delhi

    ReplyDelete
  8. Spolu offers OnePlus, Mi, Vivo, Lenovo & iPhone all types od mobile mobiles repair service at your doorstep. All our phone repairs come with 6 months warranty, same day service. We'll send you a text with a link to download the app.
    You can download the mobile app here-
    Doorstep Mobile Repair Service in Noida

    ReplyDelete
  9. Orel State University which is also known as Government State Educational Institution of Higher Education is identified as a prime higher education Institution in the metropolis of Orel. Orel State University was founded in 1931 as an industrial-Pedagogical Institute. In 1932 Orel Pedagogical University became Orel State University. Orel State University is unique in many aspects.
    To get Admission and more information-
    Orel State Medical University

    ReplyDelete
  10. Packers and Movers Chennai Give Safe and Reliable ***Household Shifting Services in Chennai with Reasonable ###Packers and Movers Price Quotation. We Provide Household Shifting, Office Relocation, ✔ ✔ ✔ Local and Domestic Transportation Services, Affordable and Reliable Shifting Service Charges @ Packers And Movers Chennai

    ReplyDelete
  11. Your site is truly cool and this is an extraordinary moving article..@
    Packers and Movers Ahmedabad

    ReplyDelete
  12. I am really enjoying reading your well written articles. I think you spend numerous effort and time updating your blog. @ Packers And Movers Bangalore

    ReplyDelete
  13. We performed at Wild Casino from completely different cellular gadgets and tablets, and the gameplay was smooth and pleasant each time. Their website is perfectly optimized for the smaller screens of smartphones. If your first deposit is made using fiat cash, you will be be} rewarded with a 250% deposit up to as} $1,000. However, it ought to be famous that the wagering requirement is 45x for the crypto welcome bonus, while for the fiat supply, it is 35x. The largest advantage of this online on line casino is that it processes payouts really 온라인카지노 quick.

    ReplyDelete