Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
coagulance
Yak Posting Veteran
78 Posts |
Posted - 2010-06-03 : 08:39:34
|
| Hi , The below query gives me the results when there are CastIDs for a ProductionDay , I would like to have the results indicate for days of the month when there is no production as '0'.[Code]Declare@dtProductionDay datetimeset @dtProductionDay = GETDATE()-45 -- Define the CTE expression name and column list.;WITH Casts_CTE (CastID, ProductionDay, ProductionMonth)AS-- Define the CTE query.( SELECT DISTINCT CastID, ProductionDay, ProductionMonth FROM List_Jobs WHERE CastID IS NOT NULL)-- Define the outer query referencing the CTE name.SELECT COUNT(CastID) AS Total, ProductionDay AS Dy,ProductionMonth AS MnFROM Casts_CTEWHERE ProductionMonth = DATEPART(MONTH,@dtProductionDay)GROUP BY ProductionMonth,ProductionDayORDER BY ProductionMonth,ProductionDay ;GOResult:Total Dy Mn25 1 415 3 47 4 425 5 417 6 41 7 433 8 413 9 410 10 415 12 41 13 415 14 41 15 4Result Needed:Total Dy Mn25 1 40 2 415 3 47 4 425 5 417 6 41 7 433 8 413 9 410 10 415 12 41 13 415 14 41 15 40 16 40 17 4....SO ON0 30 4[/CODE] |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-06-05 : 07:20:35
|
| you need to have a calendar table for that. left join your table with it and use ISNULL to convert null values to 0------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|