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 |
|
stormcandi
Starting Member
46 Posts |
Posted - 2008-04-17 : 00:18:07
|
| I have a Dataset that I am populating from a SQL Query. I am then using the dataset to populate a report in Reporting Services. What I want to do is return a standard number of rows in my dataset. (Let's say 10.) Even if my query does not have any rows in it, I want 10 empty rows returned to the dataset. If my query has 7 rows in it then I want to add on 3 empty rows and return it. I will not have more than the standard number of rows.I cannot get the table in the report to show up if the dataset is empty, but still want the table to display with 10 empty rows. I have searched how to do this online but am getting nowhere. (I know how to add one empty row but not a set number. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-17 : 00:28:06
|
| What is the need for displaying empty rows in your report? |
 |
|
|
stormcandi
Starting Member
46 Posts |
Posted - 2008-04-17 : 00:32:39
|
quote: Originally posted by visakh16 What is the need for displaying empty rows in your report?
The reason why is because I need to allow entry fields for the report so when it is printed there are empty fields for the user to enter information in. |
 |
|
|
bfoster
Starting Member
30 Posts |
Posted - 2008-04-17 : 08:47:24
|
| As long as the data table has more than 10 rows total this could be one way to approach the problem. If this won't work for you, try to be more specific about your requirements.DECLARE @Count INTSELECT @Count = CASE WHEN COUNT(*) > 10 THEN 0 ELSE 10 - COUNT(*) ENDFROM MyDataWHERE MyCondition = whateverSELECT Column1, Column2, Column3FROM MyDataWHERE MyCondition = whateverUNION ALLSELECT TOP(@Count) NULL, NULL, NULLFROM MyData |
 |
|
|
stormcandi
Starting Member
46 Posts |
Posted - 2008-04-21 : 17:52:34
|
quote: Originally posted by bfoster As long as the data table has more than 10 rows total this could be one way to approach the problem. If this won't work for you, try to be more specific about your requirements.DECLARE @Count INTSELECT @Count = CASE WHEN COUNT(*) > 10 THEN 0 ELSE 10 - COUNT(*) ENDFROM MyDataWHERE MyCondition = whateverSELECT Column1, Column2, Column3FROM MyDataWHERE MyCondition = whateverUNION ALLSELECT TOP(@Count) NULL, NULL, NULLFROM MyData
I have tried this in this query:Select @Count = CASE WHEN COUNT(*) > 10 THEN 0 ELSE 10 - COUNT(*) ENDFrom Plan Inner Join Course ON Plan.CourseID = Course.CID Where ID IN (@ID) And Plan.Grade = 10Select (Plan.ID + ' ' + CN) as Course, From Plan Inner Join Course ON Plan.CourseID = Course.CID Where ID IN (@ID) And Plan.Grade = 10UNION ALLSelect Top(@Count) nullFrom PlanBut Sql Server doesn't like my Select Top(@Count) null From Plan portion of the query. Can you see if I am overlooking something? |
 |
|
|
Greg Larsen
Starting Member
1 Post |
Posted - 2008-04-21 : 21:10:26
|
| I think this might get what you want.set nocount oncreate table x (id char(1))insert into x values('A')insert into x values('B')insert into x values('C')create table dummy (id char(1))insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)declare @count intselect COUNT(*) from x Select @Count = CASE WHEN COUNT(*) > 10 THEN 0 ELSE 10 - COUNT(*) ENDFrom xprint @countSelect id from xUNION ALLSelect Top(@Count) idFrom dummy drop table x, dummyFor more sql server examples check out http://sqlserverexamples.com |
 |
|
|
stormcandi
Starting Member
46 Posts |
Posted - 2008-04-23 : 14:59:21
|
That worked wonderfully. Is what I ended up doing is Setting the Row Count to make sure that I only received 10 rows back.Thanks a bunch! quote: Originally posted by Greg Larsen I think this might get what you want.set nocount oncreate table x (id char(1))insert into x values('A')insert into x values('B')insert into x values('C')create table dummy (id char(1))insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)insert into dummy values(null)declare @count intselect COUNT(*) from x Select @Count = CASE WHEN COUNT(*) > 10 THEN 0 ELSE 10 - COUNT(*) ENDFrom xprint @countSelect id from xUNION ALLSelect Top(@Count) idFrom dummy drop table x, dummyFor more sql server examples check out http://sqlserverexamples.com
|
 |
|
|
|
|
|
|
|