Click here to Skip to main content
15,923,120 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Table Employee

emp_id | emp_name

01 | john

02 | mitch


Table Salary

s_id | income | emp_id
1 | 10,000 | 02
2 | 20,000 | 01
3 | 5,000 | 02
4 | 2,000 | 01


I want sql command to output the data like this:

john | 20,000 | 2,000
mitch | 10,000 | 5,000


pls help me. I use VB.NET programming language
Posted
Updated 17-Jun-12 20:19pm
v2

Looks like PIVOT may provide an answer[^] to your problem.
 
Share this answer
 
I want sql command to output the data like this:
Did you try anything by yourself?

Having data for employee row-wise would be simple, like:
SQL
SELECT
  em.emp_name,
  sa.income
FROM
  Employee em
INNER JOIN
  Salary sa
ON em.emp_id = sa.emp_id


But, what you ask after this is to collate all the same employee id row data to column data. It would not be simple through query. I would suggest you to take the above query data and then mould it into the format required in your frontend.
 
Share this answer
 
Comments
Member 8439254 18-Jun-12 4:24am    
My problem is for frontend displaying of data.
Sandeep Mewara 18-Jun-12 5:16am    
Once you have this data from the query I specified, loop through the datatable. Create a new datatable and add/copy details in the format you want. You can loop and see/find all records to copy for an employee. So, copy employee wise data.
use pivot table

SQL
with Employee_Sal as
(select A.emp_name,
B.income,
from Employee A join Salary B on A.emp_id = B.emp_id)
 
Share this answer
 
Comments
Member 8439254 18-Jun-12 3:58am    
I can't find a basic example regards on pivot sql. I read many codes but don't im in trouble to make my own code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900