Solved

SQL View to include values in Annual Quarters

Posted on 2011-09-21
3
282 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
ID: 36573184
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
ID: 36573197
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
ID: 36573230
Great Thanks Lee
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need help debbuging stored procedure 21 34
SQL profiler equivalent in MS-Access 3 44
SQL Help - SELECT Statement 6 40
Get Duration of last Status Update 4 31
In this article I will describe the Detach & Attach 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.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
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, f…

895 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

13 Experts available now in Live!

Get 1:1 Help Now