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.
| Author |
Topic |
|
sqlserverlearner
Starting Member
21 Posts |
Posted - 2009-01-13 : 11:00:44
|
| I have 2 tables which need to be right joined to fill in extra rows based on another table. Pls anyone help.tabA Monthid LocId Hrs 1 10 12 2 10 15 2 12 10 3 12 9 tabB Monthid Name 1 Jan 2 Feb 3 Mar 4 Apr 5 May Result 10 Jan 12 10 Feb 15 10 Mar 0 inserted10 Apr 0 inserted10 May 0 inserted12 Jan 0 inserted12 Feb 10 12 Mar 9 12 Apr 0 inserted12 May 0 inserted |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-13 : 11:20:16
|
| [code]SELECT m.LocId,m.MonthName,COALESCE(a.Hrs,0)FROM(SELECT t.LocId,b.Monthid,b.MonthNameFROM(select distinct LocId FROM tabA)tCROSS JOIN tabB b)mLEFT JOIN tabA aON a.Monthid=m.MonthidAND a.LocId=m.LocId[/code] |
 |
|
|
sqlserverlearner
Starting Member
21 Posts |
Posted - 2009-01-13 : 12:38:02
|
| Thank You very much. I modified as per my requirement and got exactly what I wanted. I appreciate all the help. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-13 : 12:47:17
|
welcome |
 |
|
|
|
|
|