Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to write query to show in desired table fomat Expand / Collapse
Author
Message
Posted Thursday, June 27, 2013 3:58 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, August 27, 2014 9:28 AM
Points: 48, Visits: 273
Hi,
i have a requirement in sql server 2005 i have 2 tables as follows in both tables column "name" as common

Example :Below is table A

-------------------------------------
name JANclient
----------------------------------------
Srinivas ABC

suraj XYZ

Srinivas KKKK

Raj SSSS

Example:Table B
------------------------------------
name FEBclient
--------------------------------------------
Srinivas AAAA

suraj ZZZZ

mahesh PPP


now i want the result both tables A and B as shown like below

-----------------------------------------------------------------------------------
name JANclient FEBclient
-------------------------------------------------------------------------------------
Srinivas ABC AAAA

Srinivas KKK NULL

suraj XYZ ZZZZ

mahesh NULL PPP

Raj SSSS NULL



please help me
Thanks


Post #1468373
Posted Thursday, June 27, 2013 5:15 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 5:10 PM
Points: 3,902, Visits: 8,836
How do you define that you want to Join Srinivas AAAA with Srinivas ABC but not with Srinivas KKKK?

Could you provide DDL and sample data in a consumable format? That way we can focus on the solution and not on preparing the data to work on it.



Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1468393
Posted Friday, June 28, 2013 9:25 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, November 18, 2014 3:45 AM
Points: 2,873, Visits: 5,188
you need to use FULL OUTER JOIN
SELECT   ISNULL(t1.name, t2.name) AS name
,t1.JANclient
,t2.FRBClient
FROM Table1 AS t1
FULL OUTER JOIN Table2 AS t2 ON t2.name = t1.name

However, as "name" is highly unlikely to be unique, you are going to have screwed results.



_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1468590
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse