Solved

Not able to get a Proper SQL QUerry

Posted on 2008-10-27
3
165 Views
Last Modified: 2012-05-05
Hi Here is my question:

I have a table in Database like

Manager   TicketID   Ticket Arrival
X                111         10-11-2008
Y               112          09-20-2008
X               113          08-22-2008
Y               114          07-22-2008
Z               115          10-5-2008

Now i want a select query which will fetch me results something like this

Manager     NoofTickets     AgingofTickets(0-15 days)    Aging(15-30 days)   Aging(more than 30 days)
X                        2                            0                                       1                                   1
Y                        2                            0                                       0                                   2
Z                        1                            0                                       1                                   0

Where age of ticket is calculated by (Current Date - TicketArrivaldate) and based on that they are placed in 3 categories.

Can anyone tell me the SQL querry to acheive these kind of results.
After this i want to transform that to XmL and they apply XSL to it.

Any kind of help is appreciated
0
Comment
Question by:Needful
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22815641
this should do:
SELECT Mananger
, count(*)
, sum(case when Ticket_Arrival >= dateadd(day, -15, getdate()) and Ticket_Arrival <= getdate() then 1 else 0 end) Age_less_15_days
, sum(case when Ticket_Arrival >= dateadd(day, -30, getdate()) and Ticket_Arrival < dateadd(day, -15, getdate()) then 1 else 0 end) Age_15_to_30_days
, sum(case when Ticket_Arrival < dateadd(day, -30, getdate()) then 1 else 0 end) Age_more_than_30_days
fro yourtable
group by manager

Open in new window

0
 

Author Closing Comment

by:Needful
ID: 31510465
Hi Thanks a lot for the above solution:
I have further requirement of converting that to an XML File as shown below:


 
    0
    1
    3
 
 
    0
    1
    3
 
 
    0
    1
    3
 


and then apply XSL:
SO that
Entries of column Age_less_15_days is shown with Green Indicator
Entries of column Age_15_to_30_days is shown with yellow Indicator
Entries of column Age_more_than_30_days is shown with red Indicator

Can you help me with this.
Anyways thanks for your quick response


0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 22816860
i am no XML/XSL stuff worker, so I won't really be helpful there..
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Getting certain data from a string 1 24
Shop sales Actual vs Forecast 2 26
SQL JOIN 6 32
SQL JOIN + SUBQUERY? 3 6
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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

706 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

15 Experts available now in Live!

Get 1:1 Help Now