Solved

Sql help

Posted on 2011-02-16
5
179 Views
Last Modified: 2012-05-11
Hi,
I am trying to write sql to find the info based on a particular field, grouped by date (quarter)
The sql works fine but I have two more points,
1. Be able to add the DatePart(year, date) to the date columns - so that we know which year quarter it is
As you can see in below code it would be adding 2010 q1 + 2011 q1
Need to get over that
First is most important
2. Is there any way,
That I could change the above sql to have count(MAN) for multiple models?
Displayed as this model had count = this - in particular quarter
select DatePart(quarter, date) as date1,  count(MAN)
from table
where DatePart(year, date) >= '2010'
and model = 'Particular'
group by DatePart(quarter, date)

Open in new window

0
Comment
Question by:SameerMirza
[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
  • 3
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34905781
please try this:
select model, DatePart(year, date), DatePart(quarter, date) as date1,  count(MAN)
from table
where DatePart(year, date) >= 2010
group by model, DatePart(year, date), DatePart(quarter, date) 

Open in new window

0
 

Author Comment

by:SameerMirza
ID: 34905922
thanks angel. But issue is to have done somthing like
DatePart(quarter, date) + '/' + DatePart(year, date)
Problem rises when it comes to the data conversion related issue
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 34905932
you mean:
select model
, cast(DatePart(year, date) as varchar(10)) + '/' + cast( DatePart(quarter, date) as varchar(10)) as date1,  count(MAN)
from table
where DatePart(year, date) >= 2010
group by model, cast(DatePart(year, date) as varchar(10)) + '/' + cast( DatePart(quarter, date) as varchar(10))

Open in new window

0
 

Author Comment

by:SameerMirza
ID: 34907604
yes. Its perfact
0
 

Author Closing Comment

by:SameerMirza
ID: 34907605
thx
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ms sql + top 1 for each customer 3 70
Replace Dates in query 14 58
How to resolve SQL Server DB deadlock which makes my application hangs ? 6 75
Parse this column 6 38
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

759 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