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 |
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2009-10-06 : 06:21:14
|
| Hi,I have the following data:Product, platform, Region, Group, Unitstoys, floor, uk, 1, 100toys, floor, us, 1, 400pens, table, us, 1, 300The issue I am having is I have a table which generates data on a report based on the users selection.The table structure is: Uk, US, TotalProduct Value, Value, ValueObviously when they select a product that doesnt have data for neither UK OR US then the column in the table doesnt show and the table is shrinks. Any ideas/instructions on how I would go about returning value 0 pens to populate the region, instead of shrinking the table.Hope that makes sense.thanks |
|
|
sanoj_av
Posting Yak Master
118 Posts |
Posted - 2009-10-06 : 06:40:53
|
| Can you post the query you written and what will be the user input? |
 |
|
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2009-10-06 : 06:43:22
|
Select Product, [Platform], Region, [Group], 'Units' AS InfoType, CAST(ROUND(SUM(Units), 0) AS float) AS Value, '1' AS sortFROM dashboardWHERE (Product IN (Select value from dbo.ufn_Split(@product,','))) AND (Country in (Select value from dbo.ufn_Split(@country,',')))GROUP BY Product, Platform, Region, [Group]HAVING (FreePaid = 'Paid')quote: Originally posted by sanoj_av Can you post the query you written and what will be the user input?
|
 |
|
|
sanoj_av
Posting Yak Master
118 Posts |
Posted - 2009-10-06 : 06:57:20
|
| use GROUP BY ALL instead of GROUP BY and use a ISNULL() function to Units field to dispaly it as zero. |
 |
|
|
sanoj_av
Posting Yak Master
118 Posts |
Posted - 2009-10-06 : 07:01:03
|
| I mean,Select Product, [Platform], Region, [Group], 'Units' AS InfoType, CAST(ROUND(ISNULL(SUM(Units),0), 0) AS float) AS Value, '1' AS sortFROM dashboardWHERE (Product IN (Select value from dbo.ufn_Split(@product,','))) AND (Country in (Select value from dbo.ufn_Split(@country,',')))GROUP BY ALL Product, Platform, Region, [Group] |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2009-10-06 : 07:09:33
|
From BOL: Non-ISO Compliant SyntaxALL This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Includes all groups and result sets, even those that do not have any rows that meet the search condition specified in the WHERE clause. When ALL is specified, null values are returned for the summary columns of groups that do not meet the search condition. You cannot specify ALL with the CUBE or ROLLUP operators.GROUP BY ALL is not supported in queries that access remote tables if there is also a WHERE clause in the query. GROUP BY ALL will fail on columns that have the FILESTREAM attribute. http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
cipriani1984
Constraint Violating Yak Guru
304 Posts |
Posted - 2009-10-06 : 08:33:54
|
Any other solutions then to using all?quote: Originally posted by DonAtWork From BOL: Non-ISO Compliant SyntaxALL This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature. Includes all groups and result sets, even those that do not have any rows that meet the search condition specified in the WHERE clause. When ALL is specified, null values are returned for the summary columns of groups that do not meet the search condition. You cannot specify ALL with the CUBE or ROLLUP operators.GROUP BY ALL is not supported in queries that access remote tables if there is also a WHERE clause in the query. GROUP BY ALL will fail on columns that have the FILESTREAM attribute. http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp
|
 |
|
|
|
|
|
|
|