Solved

SQL Date Query

Posted on 2013-01-08
2
194 Views
Last Modified: 2013-01-08
Hi All i have the following query which all works fine

SELECT     TOP (100) PERCENT CAST(DATENAME(Month, Month) AS varchar) + ' ' + CAST(YEAR(Month) AS varchar) AS Month, COUNT(Sales_Order) AS Total_Ord, 
                      COUNT(Passed_Delivery) AS Passed, 100 * (COUNT(Passed_Delivery) / CAST(COUNT(Sales_Order) AS float)) AS Percentage, Month_No, Year_No
FROM         dbo.SC21_Customers
GROUP BY CAST(DATENAME(Month, Month) AS varchar) + ' ' + CAST(YEAR(Month) AS varchar), Month_No, Year_No

Open in new window


however aswell as keeping all of the previous dates and years etc, i now need it to include 2013 data, can anybody help to ammend it.

John
0
Comment
Question by:pepps11976
2 Comments
 
LVL 2

Expert Comment

by:thombeck
ID: 38754143
Hi,

what do you mean with include 2013 data?
Can you please provide a sample, what you are expecting?
0
 
LVL 42

Accepted Solution

by:
EugeneZ earned 500 total points
ID: 38754153
there is no limit in your query

if you have 2013 data in your table - you should be ok -- if it is still problem select RAW data

select * FROM         dbo.SC21_Customers
where Year_No =2013 and post scrubbed (without real info!) data here
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

803 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