sql server 2008 - joining two sql statements in a stored procedure - (no same columns) -


i have situation deals 2 sets of data different columns. know use union union requires equal number of expressions in both tables. trying join these 2 statements in stored procedure. first statement has 1 column 'location'

select    tablea.name,   tableb.occupation,   tablea.location,   'group1' [groupby]  tablea,  tableb  tablea.id = 1  select    tablea.name,   tableb.occupation,   'group2' [groupby]  tablea,  tableb  tableb.id = 10 

my result should this

name    occupation      groupby   location david   doctor          group1    usa john    pilot           group1    asia dwayne  wrestler        group2    null axel    rockstar        group2    null  

my table structure

table  id name  occupation location  1  david doctor     usa 1  john  pilot      asia 2  mike  clerk      europe   table b   id  name   occupation 3   wayne  writer 4   shane  publisher 10  dwayne wrestler 10  axel   rockstar 

that's called union; manually add ", null" select list in second query

add many of them need, whereever need them. if need additional columns in both tables, instances of null in first table must aliasd appropriate column name.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -