x

Displaying mutiple rows as mutiple in columns.

Hi ,

I have one problem, displaying data in columns.

I have EX: emptable

                    
empid    Sal                    
                    
1         10                    
2         20                    
3         30                    
4         40                    
5         50                    
.                    
.                    
.                    
.                    
                    
100                     
.                    
.                    
Etc                    

i want this change in multiple differnt columms, in select query or in store procedure any way

Ex: Empid as header and sal as columun

                    
1   2   3   4   5  ..... 100 etc                    
10  20  30  40  50 .......... etc.                    

Please help in how slove this problem

Thanks
Raja

more ▼

asked Nov 12, 2009 at 08:25 AM in Default

venkatesh gravatar image

venkatesh
1 1 1 1

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

You need a Cross-tab or Pivot

For example see: http://weblogs.sqlteam.com/jeffs/archive/2005/05/02/4842.aspx

more ▼

answered Nov 12, 2009 at 08:38 AM

Kristen gravatar image

Kristen ♦
2.2k 6 7 10

(comments are locked)
10|1200 characters needed characters left
more ▼

answered Nov 12, 2009 at 09:25 AM

Madhivanan gravatar image

Madhivanan
1.1k 1 3 6

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1945
x77

asked: Nov 12, 2009 at 08:25 AM

Seen: 891 times

Last Updated: Nov 12, 2009 at 08:36 AM