SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 data display (Resolved)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aakcse
Aged Yak Warrior

India
517 Posts

Posted - 08/08/2012 :  10:46:30  Show Profile  Reply with Quote
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  Show Profile  Reply with Quote
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

India
517 Posts

Posted - 08/08/2012 :  11:09:59  Show Profile  Reply with Quote
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

India
47023 Posts

Posted - 08/08/2012 :  11:18:54  Show Profile  Reply with Quote
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

India
517 Posts

Posted - 08/08/2012 :  14:12:38  Show Profile  Reply with Quote
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

India
47023 Posts

Posted - 08/08/2012 :  14:17:58  Show Profile  Reply with Quote
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

USA
15557 Posts

Posted - 08/08/2012 :  14:19:06  Show Profile  Visit robvolk's Homepage  Reply with Quote
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

India
517 Posts

Posted - 08/08/2012 :  14:49:45  Show Profile  Reply with Quote
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000