I have a matrix that totals hits per person by month, 1-12. There are no hits per month for the first 4 months of the year but my boss wants those columns to show anyway. I pasted my query below. How is this done. select name, rank, datepart(MM, date) , count(*) from log group by name, rank, date the results show 4,5,6,7,8,9,10,11,12, but no 1,2,3 since no records.
How do you code that? [quoted text, click to view] "Steve MunLeeuw" wrote: > Can you do a cross join with a static list of columns? > > Steve MunLeeuw > > > "Brian L" <BrianL@discussions.microsoft.com> wrote in message > news:50874969-CAF6-4F59-A6CC-B19D520AA877@microsoft.com... > >I have a matrix that totals hits per person by month, 1-12. There are no > >hits > > per month for the first 4 months of the year but my boss wants those > > columns > > to show anyway. I pasted my query below. How is this done. > > > > select name, rank, datepart(MM, date) , count(*) > > from log > > group by name, rank, date > > > > the results show 4,5,6,7,8,9,10,11,12, but no 1,2,3 since no records. > > > > > >
Let me rephrase that. Since the value of the column is between 1 and 12, how do you type the expression? =!Fields.Date.Value=1? [quoted text, click to view] "Brian L" wrote: > How do you code that? > > "Steve MunLeeuw" wrote: > > > Can you do a cross join with a static list of columns? > > > > Steve MunLeeuw > > > > > > "Brian L" <BrianL@discussions.microsoft.com> wrote in message > > news:50874969-CAF6-4F59-A6CC-B19D520AA877@microsoft.com... > > >I have a matrix that totals hits per person by month, 1-12. There are no > > >hits > > > per month for the first 4 months of the year but my boss wants those > > > columns > > > to show anyway. I pasted my query below. How is this done. > > > > > > select name, rank, datepart(MM, date) , count(*) > > > from log > > > group by name, rank, date > > > > > > the results show 4,5,6,7,8,9,10,11,12, but no 1,2,3 since no records. > > > > > > > > > >
Can you do a cross join with a static list of columns? Steve MunLeeuw [quoted text, click to view] "Brian L" <BrianL@discussions.microsoft.com> wrote in message news:50874969-CAF6-4F59-A6CC-B19D520AA877@microsoft.com... >I have a matrix that totals hits per person by month, 1-12. There are no >hits > per month for the first 4 months of the year but my boss wants those > columns > to show anyway. I pasted my query below. How is this done. > > select name, rank, datepart(MM, date) , count(*) > from log > group by name, rank, date > > the results show 4,5,6,7,8,9,10,11,12, but no 1,2,3 since no records. > >
Ahh, sorry, should have been more precise, cross-join in the sql select statement. I use a table valued function with my static matrix column headers, then use a CROSS JOIN to it For example: SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS OFF GO if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_GetAssessmentSeries]') and xtype in (N'FN', N'IF', N'TF')) drop function [dbo].[fn_GetAssessmentSeries] GO CREATE FUNCTION fn_GetAssessmentSeries() RETURNS @AssessmentSeries TABLE ( SeriesName varchar(250), SeriesSort int, ChartSort int, FilterFromChart int, stType varchar(100) )AS /****************************************************************************** ** File: ** Name: fn_GetAssessmentSeries ** Desc: Creates a table of series values. Not all series contain data, cross joining ** to this table allows us to create matrix queries with no missing columns. ** ** Parameters: ** Input Output ** ---------- ----------- ** ** Change History ******************************************************************************* ** Author: Date: Description: ** -------- -------- ------------------------------------------- ** Steve MunLeeuw07/06/2006 Created for Assessment reports *******************************************************************************/ BEGIN INSERT INTO @AssessmentSeries SELECT 'Students Tested', 0, null, 0, 'Count' UNION SELECT 'Percent Tested', 1, null, 0, 'Percent' UNION SELECT 'Mean Scaled Score', 2, null, 0, 'Score' UNION SELECT 'Far Below Basic', 3, 2, 1, 'Percent' UNION SELECT 'Below Basic', 4, 1, 1, 'Percent' UNION SELECT 'Basic', 5, 0, 1, 'Percent' UNION SELECT 'Proficient', 6, 3, 1, 'Percent' UNION SELECT 'Advanced', 7, 4, 1, 'Percent' UNION SELECT 'Below Proficient', 8, null, 0, 'Percent' UNION SELECT 'At or above Proficient', 9, null, 0, 'Percent' RETURN END GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO Here's part of my select clause: Stat.SeriesName, Stat.SeriesName, Stat.SeriesSort, Stat.ChartSort, Stat.FilterFromChart, Stat.stType FROM vw_rpt_Assessments v INNER JOIN StudentGroupSet sgs ON v.StudentGroupSetID = sgs.studentGroupSetID INNER JOIN Assessment a ON v.AssessmentID = a.AssessmentId INNER JOIN GradeLevel gl ON v.GradeLevelID = gl.GradeLevelID CROSS JOIN fn_GetAssessmentSeries() AS Stat [quoted text, click to view] "Brian L" <BrianL@discussions.microsoft.com> wrote in message news:B4F5E66F-041C-4A5E-9B21-9B4A67F3E008@microsoft.com... > Let me rephrase that. Since the value of the column is between 1 and 12, > how > do you type the expression? =!Fields.Date.Value=1? > > "Brian L" wrote: > >> How do you code that? >> >> "Steve MunLeeuw" wrote: >> >> > Can you do a cross join with a static list of columns? >> > >> > Steve MunLeeuw >> > >> > >> > "Brian L" <BrianL@discussions.microsoft.com> wrote in message >> > news:50874969-CAF6-4F59-A6CC-B19D520AA877@microsoft.com... >> > >I have a matrix that totals hits per person by month, 1-12. There are >> > >no >> > >hits >> > > per month for the first 4 months of the year but my boss wants those >> > > columns >> > > to show anyway. I pasted my query below. How is this done. >> > > >> > > select name, rank, datepart(MM, date) , count(*) >> > > from log >> > > group by name, rank, date >> > > >> > > the results show 4,5,6,7,8,9,10,11,12, but no 1,2,3 since no records. >> > > >> > > >> > >> > >> >
Did you understand the cross join suggestion? It's a way to add columns that will always show up. Also the "union" command is a way to add data to a query as well. -- "Everyone knows something you don't know" [quoted text, click to view] "Brian L" wrote: > Let me rephrase that. Since the value of the column is between 1 and 12, how > do you type the expression? =!Fields.Date.Value=1? > > "Brian L" wrote: > > > How do you code that? > > > > "Steve MunLeeuw" wrote: > > > > > Can you do a cross join with a static list of columns? > > > > > > Steve MunLeeuw > > > > > > > > > "Brian L" <BrianL@discussions.microsoft.com> wrote in message > > > news:50874969-CAF6-4F59-A6CC-B19D520AA877@microsoft.com... > > > >I have a matrix that totals hits per person by month, 1-12. There are no > > > >hits > > > > per month for the first 4 months of the year but my boss wants those > > > > columns > > > > to show anyway. I pasted my query below. How is this done. > > > > > > > > select name, rank, datepart(MM, date) , count(*) > > > > from log > > > > group by name, rank, date > > > > > > > > the results show 4,5,6,7,8,9,10,11,12, but no 1,2,3 since no records. > > > > > > > > > > > > > >
Did you understand the cross join suggestion? It's a way to add columns that will always show up. Also the "union" command is a way to add data to a query as well. -- "Everyone knows something you don't know" [quoted text, click to view] "Brian L" wrote: > Let me rephrase that. Since the value of the column is between 1 and 12, how > do you type the expression? =!Fields.Date.Value=1? > > "Brian L" wrote: > > > How do you code that? > > > > "Steve MunLeeuw" wrote: > > > > > Can you do a cross join with a static list of columns? > > > > > > Steve MunLeeuw > > > > > > > > > "Brian L" <BrianL@discussions.microsoft.com> wrote in message > > > news:50874969-CAF6-4F59-A6CC-B19D520AA877@microsoft.com... > > > >I have a matrix that totals hits per person by month, 1-12. There are no > > > >hits > > > > per month for the first 4 months of the year but my boss wants those > > > > columns > > > > to show anyway. I pasted my query below. How is this done. > > > > > > > > select name, rank, datepart(MM, date) , count(*) > > > > from log > > > > group by name, rank, date > > > > > > > > the results show 4,5,6,7,8,9,10,11,12, but no 1,2,3 since no records. > > > > > > > > > > > > > >
no, this appears to be over my head. [quoted text, click to view] "David Bienstock" wrote: > Did you understand the cross join suggestion? It's a way to add columns that > will always show up. Also the "union" command is a way to add data to a > query as well. > -- > "Everyone knows something you don't know" > > > "Brian L" wrote: > > > Let me rephrase that. Since the value of the column is between 1 and 12, how > > do you type the expression? =!Fields.Date.Value=1? > > > > "Brian L" wrote: > > > > > How do you code that? > > > > > > "Steve MunLeeuw" wrote: > > > > > > > Can you do a cross join with a static list of columns? > > > > > > > > Steve MunLeeuw > > > > > > > > > > > > "Brian L" <BrianL@discussions.microsoft.com> wrote in message > > > > news:50874969-CAF6-4F59-A6CC-B19D520AA877@microsoft.com... > > > > >I have a matrix that totals hits per person by month, 1-12. There are no > > > > >hits > > > > > per month for the first 4 months of the year but my boss wants those > > > > > columns > > > > > to show anyway. I pasted my query below. How is this done. > > > > > > > > > > select name, rank, datepart(MM, date) , count(*) > > > > > from log > > > > > group by name, rank, date > > > > > > > > > > the results show 4,5,6,7,8,9,10,11,12, but no 1,2,3 since no records. > > > > > > > > > > > > > > > > > >
Sorry about that, I'll try to write back later today. Steve MunLeeuw [quoted text, click to view] "Brian L" <BrianL@discussions.microsoft.com> wrote in message news:E233EC50-3251-4AF7-9D57-FC2B7E1F93AF@microsoft.com... > no, this appears to be over my head. > > "David Bienstock" wrote: > >> Did you understand the cross join suggestion? It's a way to add columns >> that >> will always show up. Also the "union" command is a way to add data to a >> query as well. >> -- >> "Everyone knows something you don't know" >> >> >> "Brian L" wrote: >> >> > Let me rephrase that. Since the value of the column is between 1 and >> > 12, how >> > do you type the expression? =!Fields.Date.Value=1? >> > >> > "Brian L" wrote: >> > >> > > How do you code that? >> > > >> > > "Steve MunLeeuw" wrote: >> > > >> > > > Can you do a cross join with a static list of columns? >> > > > >> > > > Steve MunLeeuw >> > > > >> > > > >> > > > "Brian L" <BrianL@discussions.microsoft.com> wrote in message >> > > > news:50874969-CAF6-4F59-A6CC-B19D520AA877@microsoft.com... >> > > > >I have a matrix that totals hits per person by month, 1-12. There >> > > > >are no >> > > > >hits >> > > > > per month for the first 4 months of the year but my boss wants >> > > > > those >> > > > > columns >> > > > > to show anyway. I pasted my query below. How is this done. >> > > > > >> > > > > select name, rank, datepart(MM, date) , count(*) >> > > > > from log >> > > > > group by name, rank, date >> > > > > >> > > > > the results show 4,5,6,7,8,9,10,11,12, but no 1,2,3 since no >> > > > > records. >> > > > > >> > > > > >> > > > >> > > > >> > > >
Don't see what you're looking for? Try a search.
|