Solved

display horizontally records

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL anywhere 11 databases 1 82
Need a replacement data type in Oracle 6 77
Steps to produce a data strategy 5 50
ORA-04071: missing BEFORE, AFTER or INSTEAD OF keyword 2 47
In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

809 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