?
Solved

SQL SERVER 2005 DateName trouble

Posted on 2009-05-06
3
Medium Priority
?
428 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

765 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