473,407 Members | 2,546 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,407 software developers and data experts.

How do I make months appear to be like 1-12 (first year of my database) and so on?

How do I create a query for a new column for my months to appear like 1-12 means the first year of my database (eg. 2008) and 13 to 24 means (2009) and 2536 (2010) and so on? Is there a way? so it is like 13 means january of 2009 and 14 means february of 2009.
Sep 2 '11 #1

✓ answered by NeoPa

Michelle:
I should have mentioned that before
Yup. That would make sense ;-)

Actually it makes it somewhat easier :
Expand|Select|Wrap|Line Numbers
  1. SELECT ([YEAR] - 2008) * 12 + [MONTH]) AS [MonthID]

10 1479
Rabbit
12,516 Expert Mod 8TB
Take the year of the date, subtract 2008, multiply by 12, then add the month number of the date.
Sep 2 '11 #2
:S
sorry Rabbit..I did not get what you mean.
Could you explain? How do I write that in the query?
Sep 2 '11 #3
NeoPa
32,556 Expert Mod 16PB
Something like :
Expand|Select|Wrap|Line Numbers
  1. SELECT (Year([YourDate]) - 2008) * 12 + Month([YourDate]) AS [MonthID]
Sep 2 '11 #4
I do not have DATE in my table actually. I should have mentioned that before
I have

ID
YEAR
MONTH
QUARTER
TIME
HOME
Sep 2 '11 #5
ADezii
8,834 Expert 8TB
You may also want to make sure that there are no NULL Values in the Date Field, and that it is >=#1/1/2008#.
  1. Sample Data (tblTest)
    Expand|Select|Wrap|Line Numbers
    1. TestDate
    2. 3 /17/2008
    3. 12/31/2009
    4. 11/30/2009
    5. 3 /3 /2009
    6. 1 /1 /2010
    7. 8 /23/2010
    8. 4 /29/2010
    9. 7 /9 /2010
    10. 12/25/2010
    11. 7 /7 /2008
    12. 3 /3 /2011
    13. 10/10/2012
    14. 6 /16/2012
    15. 5 /5 /2008
    16. 5 /23/2013
    17. 4 /30/2219
    18. 9 /1 /2014
    19. 2 /27/2007
    20. 12/31/2007
    21. 6 /25/2543
    22.  
  2. SQL Statement:
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblTest.TestDate, Month([TestDate])+((Year([TestDate])-2008)*12) AS MCode
    2. FROM tblTest
    3. WHERE (((tblTest.TestDate)>=#1/1/2008# And (tblTest.TestDate) Is Not Null));
    4.  
  3. Results:
    Expand|Select|Wrap|Line Numbers
    1. TestDate          MCode
    2. 3 /17/2008          3
    3. 12/31/2009         24
    4. 11/30/2009         23
    5. 3 /3 /2009         15
    6. 1 /1 /2010         25
    7. 8 /23/2010         32
    8. 4 /29/2010         28
    9. 7 /9 /2010         31
    10. 12/25/2010         36
    11. 7 /7 /2008          7
    12. 3 /3 /2011         39
    13. 10/10/2012         58
    14. 6 /16/2012         54
    15. 5 /5 /2008          5
    16. 5 /23/2013         65
    17. 4 /30/2219       2536
    18. 9 /1 /2014         81
    19. 6 /25/2543       6426
    20.  
Sep 2 '11 #6
ADezii
8,834 Expert 8TB
Add any additional Fields as needed:
Expand|Select|Wrap|Line Numbers
  1. SELECT tblTest.Month, tblTest.Year, ([Month]+([Year]-2008)*12) AS MCode
  2. FROM tblTest
  3. WHERE (((tblTest.Year)>=2008));
  4.  
Sep 2 '11 #7
NeoPa
32,556 Expert Mod 16PB
Michelle:
I should have mentioned that before
Yup. That would make sense ;-)

Actually it makes it somewhat easier :
Expand|Select|Wrap|Line Numbers
  1. SELECT ([YEAR] - 2008) * 12 + [MONTH]) AS [MonthID]
Sep 2 '11 #8
Rabbit
12,516 Expert Mod 8TB
The algorithm still stands. In place of the year and month functions, you use your year and month fields.
Sep 2 '11 #9
Thank you Rabbit and NeoPa again! It works! :)
Sep 2 '11 #10
and Thanks ADezii!! You three have helped me a lot!! :DD
Sep 2 '11 #11

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

Similar topics

16
by: sandy | last post by:
Hi, Using Java script I am trying to create code where when you place in the start date it automatically calculates 6 months for the experations date. For example when I place 01/01/04 as the...
2
by: sandy | last post by:
Hello, I am trying to automate a date. When typing in the issue date I want it to automatically calculate 6 months fronm the issue date and give me the Expiration date. Following is code that I am...
3
by: Joseph S | last post by:
I am having problems with the following countdown script. For some reason, the number of months is occasionally wrong. I can't quite put my finger on the problem. Any assistance or...
10
by: wideopensvt | last post by:
I'm having a display issue with Javascript pages on a new computer. Background colors don't appear within tables or frames in Internet Explorer 6. Example #1:...
9
by: Robin Tucker | last post by:
Hiya, I need to test "relative dates" in my program, such as "last six months" or "last 3 months" or "in the last week" etc. How can I do this with a DateTime structure? ie. If NodeDate...
2
by: bufbec | last post by:
I have worked on this for hours and can't come up with a solution. Hope someone can help me. I have a table called TMBS_HMAUDIT_PARMS. this table contains data to tell me how often a person is...
4
by: Erintoo | last post by:
Hi Group I think that I may have unwittingly caused MS Visual Basic to make objects that I insert into Word 2000 documents appear differently. For example, if I create a new document and...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
1
by: yaseencarter | last post by:
I have a Store proceture in which two parametres are supplied (Start Date and End date) and in the result only those months appeared which contain data, for example i gave the followig parameters: ...
4
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
Why does System.Globalization.DateTimeFormatInfo.CurrentInfo.MonthNames return 13 elements? Why does it not use the cuurent culture?
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.