473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Look at every *Third Tuesday* of the month on record ...?

maxx233
32
I need to look at/average some data from every third tuesday of each month during a specific time of day, over the course of the last 2 years. Can anyone think of ways, or recommend something to cleanly do this in one shot? I can't think of anything, and can't seem to find anything on it either. I know how to do everything that's not date sensitive if I were to look up all 24 dates of the third tuesday of the month and manually enter those into my query as conditions, or possibly 24 different queries loading up a temp table if all else fails... but I'd really like a one shot automated way of doing it that doesn't require that I update the query each time to remove some old date conditions and add more recent dates instead.

Surely there must be a way I would think, I would imagine many places would have need to compare data to see how sales are doing the 1st monday of the month as opposed to the third monday... Or to compare how all monday sales look against how all thursday sales look.. My needs are pretty much the same

Any ideas?
Feb 12 '09 #1
1 3872
Hi there, don't know if you can make use of the following but this returns a list of the 3rd Thursday every month for the last 2 years.

If you can work out a way of taking the resulting set of dates in to a WHERE IN criteria then you should be able to get what you want.

Unfortunately my skills stop at the list of dates!

Expand|Select|Wrap|Line Numbers
  1. DECLARE @myStartDate DATETIME
  2. DECLARE @myDate DATETIME
  3. DECLARE @mthCounter INT
  4. SET @myStartDate = getDate()-760
  5. SET @mthCounter = 0
  6. WHILE @mthCounter < 25
  7. BEGIN
  8.     SET @myDate = Dateadd(month, @mthCounter, @myStartDate)
  9.     PRINT CASE Datepart(weekday, CAST(CAST(year(@myDate) AS varchar) + '/' + CAST(month(@myDate) AS varchar) + '/01' AS datetime))
  10.                 WHEN 1 THEN CAST(CAST(year(@myDate) AS varchar) + '/' + CAST(month(@myDate) AS varchar) + '/19' AS datetime)
  11.                 WHEN 2 THEN CAST(CAST(year(@myDate) AS varchar) + '/' + CAST(month(@myDate) AS varchar) + '/18' AS datetime)
  12.                 WHEN 3 THEN CAST(CAST(year(@myDate) AS varchar) + '/' + CAST(month(@myDate) AS varchar) + '/17' AS datetime)
  13.                 WHEN 4 THEN CAST(CAST(year(@myDate) AS varchar) + '/' + CAST(month(@myDate) AS varchar) + '/16' AS datetime)
  14.                 WHEN 5 THEN CAST(CAST(year(@myDate) AS varchar) + '/' + CAST(month(@myDate) AS varchar) + '/15' AS datetime)
  15.                 WHEN 6 THEN CAST(CAST(year(@myDate) AS varchar) + '/' + CAST(month(@myDate) AS varchar) + '/21' AS datetime)
  16.                 WHEN 7 THEN CAST(CAST(year(@myDate) AS varchar) + '/' + CAST(month(@myDate) AS varchar) + '/20' AS datetime)
  17.             END
  18.       SET @mthCounter = @mthCounter + 1
  19. END
  20.  
Feb 12 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Mike C. Fletcher | last post by:
This month we'll be having a presentation by our own Peter Hansen regarding his use of ctypes and PySerial to create a "robot driver" (don't ask me, I just work here)... here's his summary: ...
2
by: David Morgan | last post by:
Hi Hopefully the subject says it all. Given a weekday, (1 to 7) and an occurrence with in a month, (1 to 4), I need to ascertain the date on which it first occurs in any given month and year. ...
3
by: johkar | last post by:
I need to document.write out a select list populated with the dates for the first and third Wednesday of each month. How do I get to the actual days? <select name="mySelect"> <option value="Oct...
1
by: Need Helps | last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
10
by: Jim | last post by:
I'm sure this has been asked before but I can't find any postings. I have a table that has weekly inspections for multiple buildings. What I need to do is break these down by the week of the...
1
by: Matt | last post by:
I have table that has the following fields: JobNumber WeekEndingDate ReportRequired_01 ReportRequired_02 every Friday morning the weekending date changes. I need to automatically generate...
2
Pittaman
by: Pittaman | last post by:
Hello, Sorry about the title, I had a hard time explaining this. I've done a little trick to solve a problem I was having with this third party control, and was wondering if anyone here could...
1
by: chrisdavis | last post by:
I have a submission form with data in it that is submitted into "tblSubmitter" with basic information. I need to take every third record and mark a "status" to it. For Example: (these are...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.