January 3, 2025 at 7:31 pm
Table A
ServerName ColB
ServerA C
ServerA I
ServerA L
ServerA M
ServerA N
ServerA T
ServerB D
ServerB E
ServerC C
ServerC D
ServerC E
Table B
ServerName ColB ColC ColD ColE Date
ServerA Z 100 200 ABC date1
ServerB D 1000 10 DEF date2
ServerB X 1000 10 DEF date2
ServerC C 11 12 AS DATE3
ServerC D 34 56 GH Date4
ServerC M 66 77 GL Date5
My Result should be
ServerName ColB ColC ColD ColE Date Comment
ServerA Z 100 200 ABC date1 Not present in Table A
ServerB D 1000 10D EF date2 Present in Table A
ServerB X 1000 10 DEF date2 Not present in Table A
ServerC C 11 12 AS DATE3 Present in Table A
ServerC D 34 56 GH Date4 Present in Table A
ServerC M 66 77 GL Date5 Not present in Table A
How can I get the above output.How do I join Table A and Table B
Thanks
January 3, 2025 at 7:45 pm
Where's the explanation of the pattern? One option might be a cross join and then filter it.
January 3, 2025 at 8:07 pm
SELECT B.*, CASE WHEN A.ServerName IS NULL THEN 'Not present in Table A'
ELSE 'Present in Table A' END AS Comment
FROM TableB B
LEFT OUTER JOIN TableA A ON A.ServerName = B.ServerName AND A.ColB = B.ColB
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply