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 |
|
tech_1
Posting Yak Master
129 Posts |
Posted - 2011-12-10 : 19:21:55
|
| Hi.I have 3 tables:TableA:PageIDSubPageIDTableB:PageIDTitleTableC:SubPageIDPageIDTitlewhat I want to do is to be able to join them together (for a SPROC) and using the parameters to match, with "@subPageID" being a possible NULL value.I want to return the results of Either:TableBORTableB and TableC (together) in one resultsethow can I do this? TableA is indeed joined as an FK to TableB and TableC |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-12-11 : 00:56:08
|
| [code]CREATE PROC yourProcName@subPageID int = NULLASSELECT *FROM TableA aINNER JOIN TableB bON b.PageID = a.PageIDINNER JOIN TableC cON c.SubPageID = a.SubPageIDAND c.PageID = a.PageIDWHERE (c.SubPageID =@subPageIDOR @subPageID IS NULL)GO[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|