Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Pivot Querry

Author  Topic 

dubaashu
Starting Member

10 Posts

Posted - 2012-08-18 : 10:38:21
Dear All Experts,

I am having following query for employee Master
Select Firstname , jobTitle , position from mytable

by this i am getting result as

Firstname jobTitle position
Viral Director 6
Kalpesh Regional Manager 7
Vikas Area Manager 8
Pradeep Manager 9
Dharmendra Sales Engineer 10
Sudeesh Sales Engineer 10

I Want result as :
Director Regional ManagerArea ManagerManagerSales Engineer
Viral Kalpesh Vikas Pradeep Dharmendra
Viral Kalpesh Vikas Pradeep Sudeesh

Kindly help to get desired result



Ashish gupte

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-18 : 11:08:11
ok. is there a field to relate corresponding row values?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dubaashu
Starting Member

10 Posts

Posted - 2012-08-18 : 11:32:11
Hi ,

I am having one more field called Position which is numeric and defined for Jobtitle Like when Position is 1 then Director when 2 then Regional Manager ...



Ashish gupte
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-18 : 11:41:41
quote:
Originally posted by dubaashu

Hi ,

I am having one more field called Position which is numeric and defined for Jobtitle Like when Position is 1 then Director when 2 then Regional Manager ...



Ashish gupte


Thats fine
But my question was more on field using which you determine which manager,director,regional manager etc should come in same row. There should be a relating field using which you should relate them together onto same row or is it just putting some random people together (which IMHO doesnt make any sense)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dubaashu
Starting Member

10 Posts

Posted - 2012-08-18 : 11:55:43
Yes i think you can relate with Two More field which is feild Name is Manager and Empid

Ashish gupte
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-18 : 12:12:53
quote:
Originally posted by dubaashu

Yes i think you can relate with Two More field which is feild Name is Manager and Empid

Ashish gupte


can you give full table structure with sample data?
Without which I cant understand how data is present

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dubaashu
Starting Member

10 Posts

Posted - 2012-08-18 : 12:16:29
Hi

Sample Data are as

Empid Firstname Jobtitle Position Manager
9 Viral Director 6 NULL
10 Kalpesh Regional Manager 7 9
11 Vikas Area Manager 8 10
12 Pradeep Manager 9 11
13 Dharmendra Sales Engineer 10 12
14 Sudeesh Sales Engineer 10 12



Ashish gupte
Go to Top of Page

dubaashu
Starting Member

10 Posts

Posted - 2012-08-18 : 12:36:16
Thanks It solved my problem


Ashish gupte
[/quote]
Thats fine
But my question was more on field using which you determine which manager,director,regional manager etc should come in same row. There should be a relating field using which you should relate them together onto same row or is it just putting some random people together (which IMHO doesnt make any sense)

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/


[/quote]

Ashish gupte
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-18 : 12:39:01
ok cool

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -