B4J Question SQL Query - add dummy rows if number of rows is under value x

h725

Active Member
Licensed User
Longtime User
Hello B4X community,

I have a question concerning an sql query.

I always need to get a minimum number of returned rows in an sql query. If the number
of the returned rows is under a defined number I have to add dummy rows.
If the sql query returns the defined number of rows or more, then there is no need to add extra rows.
The defined number is a variable and can change.

Example (in this case the number of minimum returned rows is 5):

Table rooms
idroom
1Room 1
2Room 2
3Room 3


"select id, room from rooms" would return the following:

1 room1
2 room2
3 room3

but I need something like that:

1 room1
2 room2
3 room3
0 empty
0 empty

Table rooms
idroom
1Room1
2Room2
3Room3
4Room4
5Room5
6Room6


In this case there is no need to add extra rows because the number of result rows is > 5.

1 room1
2 room2
3 room3
4 room4
5 room5
6 room6

Any idea?

Kind regards
h725
 
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
SELECT *
FROM (
select id, room
FROM rooms
union all
Select 0 id, 'empty room' room
union all
Select 0 id, 'empty room' room
union all
Select 0 id, 'empty room' room
union all
Select 0 id, 'empty room' room
union all
Select 0 id, 'empty room' room
) LIMIT 5

if there are less than 5 it, on of the dummies will appear
 
Upvote 1

h725

Active Member
Licensed User
Longtime User
Thanks. I edited the first post a little bit. The defined number is a variable and can change.
It can be 5, 10 or 20 etc.

I found something which goes into the direction, but the number is fixed:
 
Upvote 0

roerGarcia

Active Member
Licensed User
Longtime User
Sorry, isn't it an abuse as programmers to do something like that? Is it not easier to manipulate the size of the result and do what is necessary to present what you want?
 
Upvote 0

h725

Active Member
Licensed User
Longtime User
Hello,
thank you for your answers. I know that the task is a little bit tricky. I will explain why I need it this way and explain the background:
The used IDE is not B4J but VS .net. The reason why I am asking the question in this forum is because I got very good feedback
and solutions from the community in the past. If it is not wanted please move the thread to a appropiate theme or delete it. I would also pay
for the solution so maybe the business forum might fit ;-)

I have a control which generates a ganttchart from a database. I do not have the sourcecode of the control. The control has several advantages,
that is the reason why I would like to use this one. It has one disadvantage: It streches the height of the row depending of the quantity
of the entries. The following illustration is done with openoffice, but the principles shout be clear:)
1.png
2.png
4.png
3.png

Picture 1,2,3 current behavior, Picture 4 is the wanted behaviour.

I have no chance to loop through the resultset. I can only insert an sql query due to internal addressing the control.

Kind regards
h725
 
Last edited:
Upvote 0
Top