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
 General SQL Server Forums
 New to SQL Server Programming
 Please help

Author  Topic 

sapthagiri
Starting Member

2 Posts

Posted - 2014-06-30 : 02:30:53
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

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2014-06-30 : 08:38:34
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

2 Posts

Posted - 2014-07-01 : 00:44:53
Thanks alot

sapthagiri
9884450326
Go to Top of Page
   

- Advertisement -