| Author |
Topic  |
|
|
aakcse
Aged Yak Warrior
India
517 Posts |
Posted - 08/08/2012 : 10:46:30
|
I have 2 tables, I need to display data as below, with our joining these table
Tab1 ( col1,col2) Tab2(Col5,Col6) I want to display data in the result, where ever I have data for Tab1's Col1,col2 the corresponding Tab2 col5 & Col6 will have empty '' value vice versa
Col1 Col5 Col6 Col2
A Null Null B
Null X Y Null
-Neil |
Edited by - aakcse on 08/08/2012 14:50:30
|
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 08/08/2012 : 10:49:12
|
how are tables related? are there some common columns? if not, it doesnt make sense to show values side by side
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
aakcse
Aged Yak Warrior
India
517 Posts |
Posted - 08/08/2012 : 11:09:59
|
The tables are not related, say if table 1 has 5rec and table 2 has 7rec.
It should display 5+7 records =12 records in any order such that if I am displaying tab1 data only tab1's columns should have value tab2 columns should be blank.
-Neil |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 08/08/2012 : 11:18:54
|
i dont know why you need to do that but anyways here you go
SELECT Col1,
CAST(null as <datatype of col5>) AS Col5,
CAST(null as <datatype of col6>) AS Col6,
Col2
FROM Tab1
UNION ALL
SELECT Null,
Col5,
Col6,
Null
FROM Tab2
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
aakcse
Aged Yak Warrior
India
517 Posts |
Posted - 08/08/2012 : 14:12:38
|
this works perfectly Visakh... you rock man... I have seen most of your and few others reply in this forum, if you dont mind sir.. do you own this site?
Thanks
-Neil |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 08/08/2012 : 14:17:58
|
quote: Originally posted by aakcse
this works perfectly Visakh... you rock man... I have seen most of your and few others reply in this forum, if you dont mind sir.. do you own this site?
Thanks
-Neil
nope...i'm just a fellow poster here 
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
|
robvolk
Most Valuable Yak
USA
15557 Posts |
Posted - 08/08/2012 : 14:19:06
|
Visakh doesn't technically "own" the site, that would be Bill Graziano (graz). He just "owns" the lead in answers.  |
 |
|
|
aakcse
Aged Yak Warrior
India
517 Posts |
Posted - 08/08/2012 : 14:49:45
|
Well hats off to all, you guys are doing a great great(Can't call it as job as you are not getting paid :) :) ) help to people like us :) & Many thanks to Bill Graziano. believe me even msdn does not get this many hits for SQL Server and we need to wait for a day sometimes to get answer from msdn forum. Bill G (Gates) will soon get in touch with Bill G :)
My apology for taking little offline
-Neil |
Edited by - aakcse on 08/08/2012 14:52:03 |
 |
|
| |
Topic  |
|