Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL View to include values in Annual Quarters

Posted on 2011-09-21
3
Medium Priority
?
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

610 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