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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 data display (Resolved)

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-08-08 : 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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-08 : 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/

Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-08-08 : 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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-08 : 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/

Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-08-08 : 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
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-08 : 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/

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-08-08 : 14:19:06
Visakh doesn't technically "own" the site, that would be Bill Graziano (graz). He just "owns" the lead in answers.
Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2012-08-08 : 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
Go to Top of Page
   

- Advertisement -