Solved

SQL SERVER 2005 DateName trouble

Posted on 2009-05-06
3
420 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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 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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

713 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