SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Please help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sapthagiri
Starting Member

India
2 Posts

Posted - 06/30/2014 :  02:30:53  Show Profile  Reply with Quote
Hi,
Q1:
Emp_id Name Reporting
1 Suresh 1
2 Ramesh 2
3 kumar 3
4 rajesh 3
5 raju 3

how to disply empid name find out the reporting person

Q2:
emp_id month salary
1 jan 15000
1 feb 30000
1 mar 20000
2 jan 40000
2 feb 50000
2 mar 60000
3 jan 70000
3 Feb 80000
3 Mar 90000

disply quarter wise and grid

output:
Emp_id Jan Feb Mar
1 15000 30000 20000
2 40000 50000 60000
3 70000 80000 90000

sapthagiri
9884450326

Edited by - tkizer on 06/30/2014 13:08:35

bandi
Flowing Fount of Yak Knowledge

India
2206 Posts

Posted - 06/30/2014 :  08:38:34  Show Profile  Reply with Quote
quote:
Originally posted by sapthagiri

Hi,
Q1:
Emp_id   Name      Reporting
1       Suresh        1
2       Ramesh        2
3       kumar         3 
4       rajesh        3
5       raju          3

how to disply empid name find out the reporting person 

SELECT t.Emp_id, t.Name, t2.Name ReportingPerson
FROM TableName t
JOIN TableName t2 ON t.Reporting = t2.Emp_id

Q2:
emp_id month  salary
1      jan     15000
1      feb     30000
1      mar     20000
2      jan     40000
2      feb     50000
2      mar     60000
3      jan     70000
3      Feb     80000
3      Mar     90000

disply quarter wise and grid
SELECT *
FROM TableName
PIVOT (SUM(salary) FOR Months IN ([Jan],[Feb],[Mar]))P
output:
Emp_id  Jan       Feb         Mar   
1      15000     30000       20000
2      40000     50000       60000
3      70000     80000       90000

sapthagiri
9884450326




--
Chandu
Go to Top of Page

sapthagiri
Starting Member

India
2 Posts

Posted - 07/01/2014 :  00:44:53  Show Profile  Reply with Quote
Thanks alot

sapthagiri
9884450326
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000