Solved

SQL SERVER 2005 DateName trouble

Posted on 2009-05-06
3
413 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
Comment Utility
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
Comment Utility
select case when datename(mm, getdate()) = 'May' then datename(mm, getdate()) end 'May'
0
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
Comment Utility
you'll need one for each month
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

10 Experts available now in Live!

Get 1:1 Help Now