OLD Solution:
Create table A
(
KPI_ID Int,
Unit decimal,
Frequency decimal,
)
Create table B
(
KPI_ID Int,
Value decimal,
ValueDate Datetime,
)
select * from A ta left join B tb on ta.KPI_ID = tb.KPI_ID
Updated Solution:
Create table table1
(
KPI_ID Int,
Unit decimal,
Frequency decimal,
)
Create table table2
(
KPI_ID Int,
Value decimal,
ValueDate Datetime,
)
select * from table1
Go
select * from table1
Go
Insert into table1 (KPI_ID, Unit, Frequency)values(1001, 10, 15)
Insert into table1 (KPI_ID, Unit, Frequency)values(1002, 10, 15)
Insert into table1 (KPI_ID, Unit, Frequency)values(1003, 10, 15)
Insert into table1 (KPI_ID, Unit, Frequency)values(1004, 10, 15)
Insert into table1 (KPI_ID, Unit, Frequency)values(1005, 10, 15)
Insert into table1 (KPI_ID, Unit, Frequency)values(1006, 10, 15)
Insert into table1 (KPI_ID, Unit, Frequency)values(1007, 10, 15)
GO
Insert into table2 (KPI_ID, Value, ValueDate)values(1001, 55, '20140131')
Insert into table2 (KPI_ID, Value, ValueDate)values(1002, 50, '20140131')
Insert into table2 (KPI_ID, Value, ValueDate)values(1002, 54, '20140228')
Insert into table2 (KPI_ID, Value, ValueDate)values(1003, 53, '20140131')
Insert into table2 (KPI_ID, Value, ValueDate)values(1003, 57, '20140228')
GO
select * from table1 ta left join table2 tb on ta.KPI_ID = tb.KPI_ID WHERE CONVERT(VARCHAR(24),tb.ValueDate,112) like '201401%' OR CONVERT(VARCHAR(24),tb.ValueDate,112) IS NULL