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 |
|
evvo
Starting Member
16 Posts |
Posted - 2011-09-27 : 10:55:17
|
| Im seeking to create a datatable from 2 or 3 different database tables.Table A provides an ID and Name, so i simply grab all these instances.i then need to provide a value field for each of these entries from 1 or 2 databases depending on whether the value exists for that ID.So the order is - if Table B has a value for the ID AND users countryID i use that ELSE the value for ID AND countryID of NULLif neither of these exist i then need to check Table C for either a entry for the ID AND users country or the ID and UK entry which always exists, so the final datatable will have a value for each ID that existed in Table A.how would i construct this sql in my stored procedure? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-27 : 11:37:16
|
sounds something like belowSELECT a.ID,b.columns.....,c.columns....FROM TableA aLEFT JOIN TableB bON b.ID = a.IDLEFT JOIN TableC cON c.ID = a.ID ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|