Solved

SQL SERVER 2005 DateName trouble

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Where not exists in same table 3 66
How to use TOP 1 in a T-SQL sub-query? 14 44
CROSS APPLY 4 51
SQL query with cast 38 42
If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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