Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
In my ssrs report my month starts from February. But i want to start this from January. How to do this?Kindly help.
My query is as follows
SQL
SELECT        YEAR(Date) AS Year, DATENAME(MONTH, Date) AS MONTH, GatePassNo, Product_name, SerialNo, Customer_Name, Customer_Location, COUNT((CASE WHEN [Status] = 'Repaired by Vendor' THEN [Status] END))
                          AS Repaired, COUNT((CASE WHEN [Status] = 'Sent to Vendor for Repair' THEN [Status] END)) AS Pending, COUNT((CASE WHEN [Status] = 'Replaced with FSPL Inventory and Sent for Repair' OR
                         [Status] = 'Replaced with onsite Inventory and Sent for Repair' THEN [Status] END)) AS Replaced
FROM            Product_Details
WHERE        (Customer_Name IN (@Customer_Name)) AND (Customer_Location IN (@Customer_Location))
GROUP BY GatePassNo, Product_name, SerialNo, Customer_Name, Customer_Location, DATENAME(MONTH, Date), YEAR(Date)
Posted
Comments
ZurdoDev 13-Feb-15 8:13am    
You can Union with a select statement that gives you all 12 months so that any gaps in data are filled in.
Abdulnazark 26-Feb-15 4:24am    
your dates may be starting from February only, please check

1 solution

You can try this :

SQL
;WITH months(MonthNumber) AS
(
    SELECT 1
    UNION ALL
    SELECT MonthNumber+1
    FROM months
    WHERE MonthNumber < 12
)
SELECT LEFT(DATENAME(MONTH,DATEADD(MONTH,MonthNumber,
DATEADD(MONTH,DATEDIFF(MONTH,0,DATEADD(Year,-1*DateDiff(Year,getdate(),0),0))-1,0))),3) AS [month]
FROM months



Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900