I have joined two tables in SQL (see below) using a left outer join.
Is it possible to fill the null cells with other data?
(from fiddle)
CREATE TABLE Data1
(cost_type nvarchar(10), contract nvarchar(10))
;
INSERT INTO Data1
(cost_type, contract)
VALUES
('LABR', 'contract1'),
('EQP', ''),
('RST', 'contract1')
;
CREATE TABLE data2
(cost_type nvarchar(10), contract nvarchar(10), Name nvarchar(max))
;
INSERT INTO data2
(cost_type,contract,Name)
VALUES
('LABR','contract1','John'),
('MAT','contract1','John'),
('EQP','','')
;
Query currently being run:
select * from data1 dt1
left outer join data2 dt2 on dt1.cost_type=dt2.cost_type
The result I need is the following:
COST_TYPE CONTRACT NAME
LABR, contract1, John
EQP, contract1, John
RST, contract1, John
This result is based on finding the most used value for the CONTRACT column and replacing all of the nulls with that value. I need to do the same thing for the NAME column.