Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how to write query to show in desired table fomat


how to write query to show in desired table fomat

Author
Message
suresh0534
suresh0534
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
Points: 63 Visits: 344
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
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8484 Visits: 18082
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.
General Disclaimer:
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?


How to post data/code on a forum to get the best help: Option 1 / Option 2
Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3040 Visits: 5478
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!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search