Solved

display horizontally records

Posted on 2004-04-23
5
687 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Read about achieving the basic levels of HRIS security in the workplace.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now