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

x
?
Solved

SQL SERVER 2005 DateName trouble

Posted on 2009-05-06
3
Medium Priority
?
429 Views
Last Modified: 2012-05-06
Experts, I cannot seem to get the below query to give the output I am looking for.  I am using datename to pull out the month and year parts from the closed data of a trouble ticket, however when I use them as below I cannot use AS [MonthName] or AS [YearName] for column headers (or any other wording).  I receive an error around "AS".

Any help would be appreciated.

Thanks
Declare @txtTo varchar (10)
Declare @txtTo_2 varchar (10)
SET @txtTo = '1/1/2008'
SET @txtTo_2 = '1/1/2009'
Select Datename(mm,closed) ,Datename(yy,closed), src_sys,report#, repo_type, vz_svc_type_2,SUM(RESP_DUR/60)MTTR, chronic_cnt, cktfmt, installation_failure, total_ho,trbl_code, an_code, loc_z
From dbo.[maint_allrepotype>_2008]
Where closed >= convert(datetime, @txtTo, 101)
	
group by Datename(mm,closed),Datename(yy,closed), src_sys,report#, repo_type, vz_svc_type_2,RESP_DUR, chronic_cnt, cktfmt, installation_failure, total_ho,trbl_code,an_code, loc_z

Open in new window

0
Comment
Question by:jclem1
[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 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 24319672
Did u try it this way
Declare @txtTo varchar(10)
Declare @txtTo_2 varchar(10)
SET @txtTo = '1/1/2008'
SET @txtTo_2 = '1/1/2009'
Select  Datename(mm, closed) As [Month], Datename(yy, closed) as [year], src_sys, report#,
        repo_type, vz_svc_type_2, SUM(RESP_DUR / 60) MTTR, chronic_cnt, cktfmt,
        installation_failure, total_ho, trbl_code, an_code, loc_z
From    dbo.[maint_allrepotype>_2008]
Where   closed >= convert(datetime, @txtTo, 101)
group by Datename(mm, closed), Datename(yy, closed), src_sys, report#,
        repo_type, vz_svc_type_2, RESP_DUR, chronic_cnt, cktfmt,
        installation_failure, total_ho, trbl_code, an_code, loc_z
 

Open in new window

0
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 24320318
select case when datename(mm, getdate()) = 'May' then datename(mm, getdate()) end 'May'
0
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 24320324
you'll need one for each month
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

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