Solved

SQL View to include values in Annual Quarters

Posted on 2011-09-21
3
279 Views
Last Modified: 2012-06-27
I have a table called Opportunity with columns that return data as follows:

Oppo_OpportunityID  Oppo_userID  Oppo_Description   Oppo_Total    Oppo_CloseBy
101                              1                      3 x Widget X            1500               9/28/2011 12:00:00 AM
102                              1                      2 x Widget Y            1000              11/27/2011 12:00:00 AM
103                              2                      4 x Widget X            2000              10/20/2011 12:00:00 AM

oppo_opportunityid = int
oppo_userid = int
oppo_description = nvarchar(50)
oppo_total = numeric(24, 6)
oppo_closeby = datetime

I need to write a SQL view that returns the data to include Quarters/Year (datepart qq)
e.g.

Oppo_OpportunityID  Oppo_userID  Oppo_Description   Oppo_Total    * QQYY
101                              1                      3 x Widget X            1500                Q311
102                              1                      2 x Widget Y            1000                Q411
103                              2                      4 x Widget X            2000                Q411

Any help would be appreciated
0
Comment
Question by:MimUK
  • 2
3 Comments
 
LVL 25

Expert Comment

by:Lee Savidge
Comment Utility
Include this:


'Q' + cast(datepart(q, oppo_CloseBy) as nvarchar(1)) + right(cast(year(oppo_CloseBy) as nvarchar(4)), 2) as QQYY
0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 250 total points
Comment Utility
So:

select oppo_opportunityid, oppo_userid, oppo_description, oppo_total, oppo_closeby,
'Q' + cast(datepart(q, oppo_CloseBy) as nvarchar(1)) + right(cast(year(oppo_CloseBy) as nvarchar(4)), 2) as QQYY
from opportunity
0
 

Author Closing Comment

by:MimUK
Comment Utility
Great Thanks Lee
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
In this article I will describe the Copy Database Wizard 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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now