Solved

display horizontally records

Posted on 2004-04-23
5
699 Views
Last Modified: 2007-12-19
i have only one coloumn in a table i want to dispaly all the datas in a row.Name of the table is student which contains only one coloumns slno
Student
           Slno
           1
           2
           3
           4
           5
I want to display them as
slno 1 2 3 4 5
0
Comment
Question by:babita220004
5 Comments
 
LVL 6

Accepted Solution

by:
nathaniel earned 25 total points
ID: 10898331
in Access SQL, you may try

TRANSFORM Last(Student)
SELECT "Slno" AS Names
From Student
GROUP BY ""
PIVOT Sino;


0
 
LVL 1

Expert Comment

by:Djuradj
ID: 10898461
Display it where? On your web page, gui application,...?
Which server-side language (Script) do you use? Which DB do you use?

If you want to crete a query which will collect values of this one column (Slno) and sore it in one single row, it is only to possible to by creating temporary table with as many columns as you query returns rows. And then, to create (build) a query to insert those values into that temp table.
OR to user pivot table. You could use an OLAP (OnLine Analytical Processing) data cube to get PIVOT functionality. "Pivoting" will be supported in Yukon (next version of ms sql server), and  i am not sure about Oracle.

Anyway, to hard task, so If you can skip to do that on sql server - don't do it.
0
 
LVL 8

Assisted Solution

by:baonguyen1
baonguyen1 earned 25 total points
ID: 10898613
In Oracle if you know the maximum number of rows you can use:

SQL> select id from t1;

        ID
----------
         1
         2
         3
         4
         7
         5
         6

7 rows selected.

SQL> ed
Wrote file afiedt.buf

  1  select rtrim(
  2  max( decode( rownum, 1, id, null) ) ||','||
  3  max( decode( rownum, 2, id, null ) ) ||','||
  4  max( decode( rownum, 3, id, null ) ) ||','||
  5  max( decode( rownum, 4, id, null ) ) ||','||
  6  max( decode( rownum, 5, id, null ) ) ||','||
  7  max( decode( rownum, 6, id, null ) ) ||','||
  8  max( decode( rownum, 7, id, null ) ), ',' )
  9* from t1
SQL> /

--------------------------------------------------------------------------------
1,2,3,4,7,5,6

Or if you dont know the max of rows you can use pl/sql

SQL> ed
Wrote file afiedt.buf

  1  create or replace function column_row return varchar2
  2    is
  3        v_data varchar2(4000);
  4    begin
  5            for x in ( select id from t1 )
  6            loop
  7                    v_data := v_data || ',' || x.id;
  8            end loop;
  9            return ltrim(v_data, ',' );
 10*   end;
SQL> /

Function created.

SQL> select column_row from dual;

COLUMN_ROW
--------------------------------------------------------------------------------
1,2,3,4,7,5,6

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now