| Author |
Topic |
|
mahsa_mr
Starting Member
22 Posts |
Posted - 2010-01-15 : 14:21:32
|
| Hi ,I have a table a: with following collums:Table a:perid edesc----- ------1 ea1 eb1 ec2 ea2 ecTable b:perid ddesc----- ------1 da2 da2 dc now wants to show it as a foolowing :perid edesc ddesc------ ------ ------1 ea da1 eb null1 ec null2 ea da 2 ec dcmay you advice ?Thank you |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-15 : 14:25:34
|
| For perid1, Why does "da" have to be corresponding to "ea" and not "eb" or "ec"... |
 |
|
|
mahsa_mr
Starting Member
22 Posts |
Posted - 2010-01-15 : 14:38:51
|
| if you suppose that table "e" is the earning and table "d" are deductions , so person id : 1 can be have some earning and deduction and it's not fix for all month .and i want to have a result like that to show in pay slip. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-01-15 : 14:58:16
|
selecte.perid,e.edesc,d.ddescfrom table_a as eleft join table_b as don stuff(e.edesc,1,1,'') = stuff(d.ddesc,1,1,'')order by e.perid,e.edesc No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
shan
Yak Posting Veteran
84 Posts |
Posted - 2010-01-15 : 15:03:24
|
| see if this worksdeclare @t1 table(id int,name varchar(5))declare @t2 table(id int,name varchar(5))insert into @t1 select '1', 'ea'union allselect '1', 'eb'union allselect '1', 'ec'union allselect '2', 'ea'union allselect '2', 'ec'--select * from @t insert into @t2select '1','da'union allselect '2', 'da'union allselect '2', 'dc'select a.id,a.name,b.namefrom(select id,name ,substring(name,2,1) as sub_name,rank() over(partition by id order by id,substring(name,2,1)) as rnk from @t1)aleft outer join (select id,name,substring(name,2,1) as sub_name,rank() over(partition by id order by id,substring(name,2,1)) as rnk from @t2)bon a.rnk = b.rnk and a.id =b.id-Shan |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-01-15 : 15:08:52
|
But I really doubt if OP's actual data is similar to the sample he has shown here...especially based on his statement here. quote: if you suppose that table "e" is the earning and table "d" are deductions
My guess is he wud need something like thisselect a.id,sum(a.edesc),sum(b.ddesc)from table1 ainner join table2 b on a.id = b.idgroup by a.id But of course, I'm just speculating based on OP's comments about earnings and deductions. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-01-15 : 15:14:36
|
I agree.OP should give a better example. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
mahsa_mr
Starting Member
22 Posts |
Posted - 2010-01-15 : 23:49:57
|
| Hi Thanks all for reply .The Example of this is completely like all employee pay slip , one column hold the earning and one column for deduction .earning column is a table that have a person id , earning description and earning amount deduction column is a table that have a person id , deduction description and deduction amount now I want to show it in report and need a query to have these information together.please let me know if need more clarification . |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-01-16 : 08:40:06
|
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|