Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 > 65I found an example doing it with a stored procedure here:http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_24324701.htmlBut I've been unable to make it work for me!Thanks in advance for your helpBob
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 > 65I found an example doing it with a stored procedure here:http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_24324701.htmlBut I've been unable to make it work for me!Thanks in advance for your helpBob
Where do you want to show data?MadhivananFailing to plan is Planning to fail
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.ThanksBob
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.ThanksBob
You should be doing this in html formMadhivananFailing to plan is Planning to fail
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 > 65UNION ALLSELECT '','',''....number of columns same as in above result,numberFROM master..spt_valueswhere type='p'and number between 1 and 10)tORDER BY ord
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