Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8444657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:26:59+00:00 2026-06-10T09:26:59+00:00

I have data that, in a normal query, would appear like this: Val1 Val2

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:27:01+00:00Added an answer on June 10, 2026 at 9:27 am

    Bonus to this is if you end up with more data, it’ll just build more horizontal columns as needed but never go over 12 rows of data. The “in-SQL” way will require code changes if you ever need to display more data.

    Disclaimer: This is totally off-the-cuff (C# as that’s what I’m used to). There are probably much better ways to do this (Linq?) The logic should be pretty close, but this gives you the flexibility to use that list of data for other purposes than this very narrowly focused display.

    DataTable dt = ResultsFromSproc();
    DataTable outputDt = new DataTable();
    
    //prebuild 12 rows in outputDt
    int iRows = 12;
    while(iRows > 0) {
        outputDt.Rows.Add(new DataRow());
        iRows-=1;
    }
    
    int outputColumn = 0;
    for(int i = 0; i < dt.Rows.Count; i+=1){
        DataRow dr = dt.Rows[i];
    
        if(i % 12 == 0 && i > 0) { 
            //add two more columns to outputDt
            outputDt.Columns.Add() //Not sure but you might need to give it a name. (outputColumn+2).ToString() should work
            outputDt.Columns.Add() //Not sure but you might need to give it a name. (outputColumn+3).ToString() should work
            outputColumn += 1;
        }
        outputDt.Rows[i%12][outputColumn] = dr[0];
        outputDt.Rows[i%12][outputColumn + 1] = dr[1];
    }
    //Step2: Bind to outputDt. Step 3: Profit!
    

    ALTERNATE version: For requirement that val1 == 48 goes in cell 48 (see comments)

    DataTable dt = ResultsFromSproc();
    DataTable outputDt = new DataTable();
    
    //prebuild 12 rows in outputDt
    int iRows = 12;
    while(iRows > 0) {
        outputDt.Rows.Add(new DataRow());
        iRows-=1;
    }
    
    int outputColumn = 0;
    int iMaxCell = (int)dt.Select("MAX(Val1)")[0][0];
    //ASSUMING YOU HAVE ALREADY DONE AN ORDER BY Val1 in SQL (if not you need to sort it here first)
    for(int i = 0; i < iMaxCell; i+=1){
        DataRow dr = dt.Rows[i];
    
        if(i % 12 == 0 && i > 0) { 
            //add two more columns to outputDt
            outputDt.Columns.Add() //Not sure but you might need to give it a name. (outputColumn+2).ToString() should work
            outputDt.Columns.Add() //Not sure but you might need to give it a name. (outputColumn+3).ToString() should work
            outputColumn += 2;
        }
        //compare to i+1 if your data starts at 1
        if((int)dr[0] == (i+1)){
            outputDt.Rows[i%12][outputColumn] = dr[0];
            outputDt.Rows[i%12][outputColumn + 1] = dr[1];
        }
    }
    //Step2: Bind to outputDt. Step 3: Profit!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data that looks like this: #info #info2 1:SRX004541 Submitter: UT-MGS, UT-MGS Study:
I have data that I would like to compute some statistics with. The data
I have some data that I would like to visualize. Each byte of the
I have a data that looks like this . And I intend to create
I have a data that looks like this . And my code below simply
We have a data model that has some requirements. I would like to find
I have a LINQ query mapped with the Entity Framework that looks something like
I have a model that looks like this and stores data as key-value pairs.
I have a cache library that stores cached data in normal php files, with
I have data that is organized in kind of a key-key format, rather than

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.