July 15, 2022 at 2:16 pm
Records Refrenace | DataMaster DataKey
1 A | A 22
2 B | B 33
3 C | C 44
4 E |
5 F |
6 G |
7 H |
8 D |
9 R |
For the Above which is not in the Master data I need to set it as 'Unknown'
Record data Key
1 A 22
2 B 33
3 C 44
4 Unknown -1
5 Unknown -1
6 Unknown -1
7 Unknown -1
8 Unknown -1
9 Unknown -1
Hi,
How to get the with the help of Left Join the below data,
i need to get which ever is not in the master data should be as unknown and -1.
July 15, 2022 at 3:02 pm
My question would be, why are you using two tables to do one thing? It looks to me like it should be a single table because there appears to be a 1:1 correlation according to the data you've posted.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 15, 2022 at 4:47 pm
Ref table is something we get it predefined , where as master data is something we will be getting with some extra data sometime.
But now i think i had done.
declare @Master table ( data varchar(15), datakey int)
declare @ref table ( rid int, data varchar(15))
Insert into @Master
Select 'A', 22
UNION ALL
Select 'B', 33
UNION ALL
Select 'C', 44
insert into @ref
Select 1, 'A'
UNION ALL
Select 2, 'B'
UNION ALL
Select 3, 'C'
UNION ALL
Select 4, 'D'
UNION ALL
Select 5, 'E'
UNION ALL
Select 6, 'F'
UNION ALL
Select 7, 'G'
UNION ALL
Select 8, 'R'
select isnull(b.data,'Unknown'),isnull(b.datakey,'-1') from @ref a
left join @Master b on a.data=b.data
July 15, 2022 at 9:07 pm
My question would be, why are you using two tables to do one thing? It looks to me like it should be a single table because there appears to be a 1:1 correlation according to the data you've posted.
It's vertical partitioning. There are often good reasons to do it.
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".
September 1, 2022 at 5:50 am
Thank you Scott. I now know the naming of this type of scheme. I've seen it where the pk object has different properties based on the value in another column , 'type' related. So a master table is created with related tables.
An example would be having a table of music you have. All songs will have artist, year, name... your master table. But those of cd media type will have other columnd like track number, while those on your computer (mp3) will have mb size, folder location .. different remaining properties. So these will be different tables.
I think another advantage is faster write speeds are possible.
----------------------------------------------------
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply