![]() ![]() I was more interested in sports than technology and my original goal was to become a basketball coach so I went to college to study Physical Education. ![]() I should explain that I had little interest in computers in high school and college. I'd say my first challenge was entering the Information Technology field in the first place. The question is: “What are the largest challenges that you have faced in your career and how did you overcome those?” Ideally to solve a problem like this you would have a dates table as Jonathan recommends in the thread.įor more information on a numbers table check out these articles:Ĭhris Shaw posted a new SQL Quiz and I have been tagged by Kendal Van Dyke, so I need to take up the challenge. This case statement is important if you expect the code to work on any database in any SQL Server install. ![]() This can also be affected by using SET DATEFIRST if you want it to be different from the default for the language. Language settings affect date information. According to Books on line DATEFIRST indicates the specified first day of each week. The WHERE clause then just compares the value returned from the DATEPART function (weekday) to the value for Wednesday based on the value. Then I just run a simple select against the temporary numbers table adding each number to the first day of the year. If you don't have a numbers table already, you should as there are many good uses for it. The first section just creates a temporary numbers table and you can do that several ways, I just opted for a simple one. So here's the code:ĭATEPART ( weekday, DATEADD ( DAY, n, '' )) = The other day I answered this question at SQLServerCentral, "Need a date function to return every Wednesday of the year", and got a couple of kudos, one from Jonathan Kehayias and one from Chris Morris (frequent contributor to the SSC forums), so I thought I'd post the code here and then explain it a bit. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |