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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL table merge

Author  Topic 

altuko
Starting Member

3 Posts

Posted - 2010-07-28 : 11:38:26
Hi all,

i have 3 tables,and i wanna merge them looking at sdatekey and edatekey.

Table1
sdatekey edatekey title ID
10 15 x 12

Table2
sdatekey edatekey staffstatu reason ID
9 12 y a 12

Table3
sdatekey edatekey level tel address ID
5 11 z b c 12


i wanna this resultset;

sdatekey edatekey title staffstatu reason level address tel
5 9 NULL NULL NULL z c b
9 10 NULL y a z c b
10 11 x y a z c b
11 12 x y a NULL NULL NULL
12 15 x NULL NULL NULL NULL NULL

Ifor
Aged Yak Warrior

700 Posts

Posted - 2010-07-28 : 13:08:23
Umm… This looks like homework so I doubt if anyone will do it for you.

Try the following approach:
1. Use a Number/Tally table to replace the sdatekey and edatekey with the appropriate number of rows with datekey.
2. FULL JOIN the results.
3. Rollup the results so that consecutive datekeys become one row with sdatekey and edatekey where the other columns are the same.

Go to Top of Page

altuko
Starting Member

3 Posts

Posted - 2010-07-28 : 13:28:01
No that is not homework,it is about my job.i think that is not possible to do that:)
Go to Top of Page

altuko
Starting Member

3 Posts

Posted - 2010-07-28 : 13:31:41
may be u can give some sample code for this.u dont have to do all of that.
Go to Top of Page
   

- Advertisement -