Solved

SQL SERVER 2005 DateName trouble

Posted on 2009-05-06
3
416 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
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

22 Experts available now in Live!

Get 1:1 Help Now