Solved

SQL View to include values in Annual Quarters

Posted on 2011-09-21
3
293 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 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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 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