I have data that, in a "normal" query, would appear like this:
Val1 Val2
---- ----
1 2
2 [blank]
3 2
4
5 1
6 3
..
96 1
What I want, though, is something like this (I need to limit the number of rows to 12):
Val1 Val2 Val1 Val2 Val1 Val2 ... Val1 Val2
---- ---- ---- ---- ---- ----
1 2 13 1 25 [blank] ... 85 1
2 [blank] 14 1 26 3 ... 86 [blank]
.. ... ... ... ... ... ... ... ...
12 1 24 [blank] 36 2 ... 96 3
Is there a select statement that would give me that? I'm no SQL expert, but I'm thinking something (semantically) along these lines:
select (select val1, val2 from dbtable where val1 < 13),
(select val1, val2 from dbtable where val1 > 12 and val1 < 25),
...
(select val1, val2 from dbtable where val1 > 84)
from dbtable
UPDATE
In response to dfb's sql example:
When I do this:
SELECT t1.Val1, t1.Val2 FROM
(SELECT Val1, Val2, rownum() as rownum FROM dbTable) t1
INNER JOIN (SELECT Val1, Val2, rownum() as rownum FROM dbTable) t2
ON t1.rownum/2 == t2.rownum/2
...I get "FROM keyword not found where expected"
And when I do this (remove the "rownum()" stuff):
SELECT t1.Val1, t1.Val2 FROM
(SELECT Val1, Val2 FROM dbTable) t1
INNER JOIN (SELECT Val1, Val2 FROM dbTable) t2
ON t1.rownum/2 == t2.rownum/2
...I get "ORA-01747: invalid user.table.column, table.column, or column specification"
UPDATE 2
Sully's example came the closest, although I wish the UNION SQL would work - it would be better if it could be done without pushing down the valid values. As it is, I have the right layout but the vals are not appearing just where I need them to within that 16X12 layout. At any rate, for posterity's sake, here's how the Rows and Columns are dynamically created (not as shown in the code below, and not identical to each other):
//prebuild 12 rows in outputDt
int iRows = 12;
while (iRows > 0)
{
DataRow row = outputDt.NewRow();
outputDt.Rows.Add(row);
iRows -= 1;
}
//prebuild 16 cols in outputDt
int iCols = 16;
while (iCols > 0) {
DataColumn col = new DataColumn();
outputDt.Columns.Add(col);
iCols -= 1;
}
FINAL UPDATE
Got it working. See Is it possible to populate a DataGridView with alternating vertical columns?