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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Fixed No Results: Pad Results with Blank Rows

Author  Topic 

Mr Fett
Starting Member

28 Posts

Posted - 2009-07-23 : 10:41:46
Hi all,

Apologies for posting again so soon - I've hit another snag that I can't seem to find an answer to.

To streamline some programming I'm doing, I was wondering if it was possible to "pad" a returned dataset with blank rows to ensure I always get a minimum (or set) number of rows for example, if the statement below found only 3 results, I'd get 10 rows (7 of which were blank):

SELECT * FROM customers WHERE age > 65

I found an example doing it with a stored procedure here:

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_24324701.html

But I've been unable to make it work for me!

Thanks in advance for your help

Bob

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-23 : 10:59:01
quote:
Originally posted by Mr Fett

Hi all,

Apologies for posting again so soon - I've hit another snag that I can't seem to find an answer to.

To streamline some programming I'm doing, I was wondering if it was possible to "pad" a returned dataset with blank rows to ensure I always get a minimum (or set) number of rows for example, if the statement below found only 3 results, I'd get 10 rows (7 of which were blank):

SELECT * FROM customers WHERE age > 65

I found an example doing it with a stored procedure here:

http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_24324701.html

But I've been unable to make it work for me!

Thanks in advance for your help

Bob


Where do you want to show data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Mr Fett
Starting Member

28 Posts

Posted - 2009-07-23 : 12:43:32
Hi Madhivanan,

I'm going to be displaying this data as a HTML form - I *can* create a work around us the code but I'm looking for a cleaner more elegant solution.

Thanks

Bob
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-24 : 02:39:26
quote:
Originally posted by Mr Fett

Hi Madhivanan,

I'm going to be displaying this data as a HTML form - I *can* create a work around us the code but I'm looking for a cleaner more elegant solution.

Thanks

Bob


You should be doing this in html form

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-24 : 12:46:54
its ugly to do this in sql, but just to show it will be like

SELECT TOP 10 *
FROM
(
SELECT *,0 as ord FROM customers WHERE age > 65
UNION ALL
SELECT '','',''....number of columns same as in above result,number
FROM master..spt_values
where type='p'
and number between 1 and 10
)t
ORDER BY ord
Go to Top of Page

Mr Fett
Starting Member

28 Posts

Posted - 2009-07-24 : 15:38:48
Thanks very much - I'll give it a go.

To be honest I think its ugly wherever you do it but if I do it in a stored procedure at least I don't have to look at very often!

:-D
Go to Top of Page
   

- Advertisement -