Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sql help

Posted on 2011-02-16
5
Medium Priority
?
182 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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 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