| Author |
Topic |
|
birre69
Starting Member
5 Posts |
Posted - 2007-04-05 : 03:59:33
|
| Hello,I have to get some data out of 2 tables.Replication of the tables:Werknemer_090: NrWg_090 WnNr_090 Naam_090 Voornaam_090 10 1 test test 10 2 test2 test2 9 5 test3 test3WnTewerkstelling_092:NrWg_092 WnNr_092 VolgNr_092 Statuut_092 10 1 1 b 10 1 2 b 10 2 1 a 9 5 1 bSo I need to get Naam_090, Voornaam_090, Statuut_092. The problem is that in the table WnTewerkstelling_092, the pk = NrWg_092, WnNr_092, VolgNr_092. NrWg_092 and WnNr_092 can contain duplicate values. And I only want the employees (Werknemers) once with there statuut (statuut_092).Someone can help me?sorry of the positioning |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-05 : 04:12:20
|
| [code]-- prepare sample datadeclare @Werknemer_090 table( NrWg_090 int, WnNr_090 int, Naam_090 varchar(50), Voornaam_090 varchar(50))declare @WnTewerkstelling_092 table( NrWg_092 int, WnNr_092 int, VolgNr_092 int, Statuut_092 varchar(1))insert @Werknemer_090select 10, 1, 'test', 'test' union allselect 10, 2, 'test2', 'test2' union allselect 9, 5, 'test3', 'test3'insert @WnTewerkstelling_092select 10, 1, 1, 'b' union allselect 10, 1, 2, 'b' union allselect 10, 2, 1, 'a' union allselect 9, 5, 1, 'b'-- final queryselect t1.Naam_090, t1.Voornaam_090, t2.Statuut_092from @Werknemer_090 t1 join (select distinct NrWg_092, WnNr_092, Statuut_092 from @WnTewerkstelling_092) t2on t1.NrWg_090 = t2.NrWg_092 and t1.WnNr_090 = t2.WnNr_092[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
birre69
Starting Member
5 Posts |
Posted - 2007-04-05 : 04:31:17
|
quote: Originally posted by harsh_athalye
-- prepare sample datadeclare @Werknemer_090 table( NrWg_090 int, WnNr_090 int, Naam_090 varchar(50), Voornaam_090 varchar(50))declare @WnTewerkstelling_092 table( NrWg_092 int, WnNr_092 int, VolgNr_092 int, Statuut_092 varchar(1))insert @Werknemer_090select 10, 1, 'test', 'test' union allselect 10, 2, 'test2', 'test2' union allselect 9, 5, 'test3', 'test3'insert @WnTewerkstelling_092select 10, 1, 1, 'b' union allselect 10, 1, 2, 'b' union allselect 10, 2, 1, 'a' union allselect 9, 5, 1, 'b'-- final queryselect t1.Naam_090, t1.Voornaam_090, t2.Statuut_092from @Werknemer_090 t1 join (select distinct NrWg_092, WnNr_092, Statuut_092 from @WnTewerkstelling_092) t2on t1.NrWg_090 = t2.NrWg_092 and t1.WnNr_090 = t2.WnNr_092 Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
This works fine, tybut there is still a litle prob.NrWn Naam Voornaam Statuut2 TEST WERKNEMER SOFIE 2 TEST WERKNEMER SOFIE 0Sometimes ther are double rows because of 'statuut' that is empty in a row, but not in the other of the same employee. |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-05 : 04:34:54
|
| [code]-- prepare sample datadeclare @Werknemer_090 table( NrWg_090 int, WnNr_090 int, Naam_090 varchar(50), Voornaam_090 varchar(50))declare @WnTewerkstelling_092 table( NrWg_092 int, WnNr_092 int, VolgNr_092 int, Statuut_092 varchar(1))insert @Werknemer_090select 10, 1, 'test', 'test' union allselect 10, 2, 'test2', 'test2' union allselect 9, 5, 'test3', 'test3'insert @WnTewerkstelling_092select 10, 1, 1, 'b' union allselect 10, 1, 2, '' union allselect 10, 2, 1, 'a' union allselect 9, 5, 1, 'b'-- final queryselect t1.Naam_090, t1.Voornaam_090, t2.Statuut_092from @Werknemer_090 t1 join (select distinct NrWg_092, WnNr_092, Statuut_092 from @WnTewerkstelling_092 where Statuut_092 is not null and Statuut_092 <> '') t2on t1.NrWg_090 = t2.NrWg_092 and t1.WnNr_090 = t2.WnNr_092[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
birre69
Starting Member
5 Posts |
Posted - 2007-04-05 : 04:45:42
|
| ok,ty verry much |
 |
|
|
|
|
|