T-SQL:  Formula for Computing "Month 1", "Month 2", etc.

Posted on 2013-09-30
Medium Priority
Last Modified: 2013-09-30

I have a purchase order table that has a field called Document Date (POP10100.DOCDATE).

I need a formula that will compute "Month 1" for any such dates that are in the current month; "Month 2" for any such dates that are next month; "Month 3" for and such dates that are two months later; all the way through 18 months from now.

I have tried all variations of the T-SQL DATEPART, DATEDIFF, GETDATE, but the more I study T-SQL, the less I learn.  I just can't "get it".

Please help!


Question by:TBSupport
LVL 41

Accepted Solution

Kyle Abrahams earned 2000 total points
ID: 39533246
  'Month ' + cast(
    (datepart(M, <col>) - datepart(M, getdate()) + 1) as varchar(2))
from table
LVL 66

Expert Comment

by:Jim Horn
ID: 39533252
Give us a mockup of what your POP10100 table looks like, then fire up your Excel and mock up what you are trying to pull off here.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question