Good day some people alredy saw this qvestion from me but here i am again i made a good saple data this time
Step one 1
create table olap.sampledata1
(
[Date] date ,TC1 varchar(100),Amount_New decimal(10,2)
)
Step 2
INSERT INTO [OLAP].[sampledata1]
([Date]
,[TC1]
,[Amount_New])
VALUES ('2020-11-01','Houses:N-Home',70),
('2020-11-01','Houses:N-KL',80),
('2020-11-01','Default Category: Default Option',90),
('2020-11-01','Houses:NS-Home',22.5),
('2020-11-01','Houses:N-KL',45),
('2020-11-01','Houses:N-GR',22.5),
('2020-12-01','Houses:N-Home',100),
('2020-12-01','Default Category: Default Option',250),
('2020-12-01','Houses:N-Kl',110),
('2020-12-01','Houses:N-Home',24),
('2020-12-01','Houses:N-KL',12),
('2020-12-01','Houses:N-GR',60),
('2020-10-01','Houses:N-BR',24),
('2020-10-01','Houses:N-KL',12),
('2020-10-01','Houses:N-GR',60),
('2020-10-01','Houses:N-BR',24),
('2020-10-01','Default Category: Default Option',70)
Step 3
CREATE TABLE [OLAP].[test2](
[Name] nvarchar NULL,
[Source] nvarchar NULL,
[AllocateToTc] nvarchar NULL,
[Percent] nvarchar NULL,
[date] nvarchar NULL,
[AllocateFromTc] nvarchar NULL
GO
Step 4
INSERT INTO [OLAP].[test2]
([Name]
,[Source]
,[AllocateToTc]
,[Percent]
,[date]
,[AllocateFromTc])
VALUES
('1','User','Houses: NS-Home','25','2020-11-01','Default Category: Default Option'),
('2','User','Houses: N-KL',50', '2020-11-01','Default Category: Default Option'),
('3','User','Houses: N-GR','25', '2020-11-01','Default Category: Default Option'),
('4','User','Houses: N-Home','20', '2020-12-01','Default Category: Default Option'),
('5','User','Houses: N-KL','10', '2020-12-01','Default Category: Default Option'),
('6','User','Houses: N-GR','50', '2020-12-01','Default Category: Default Option'),
('7','User','Houses: N-BR','20', '2020-12-01','Default Category: Default Option')
Step 5
CREATE VIEW [OLAP].[VW_Deimos_view]
AS
select distinct
A1.Date,
A1.TC1,
A1.Amount_New,
case
when A1.Date = B2.Date
and a1.TC1 = b2.AllocateFromTc
then AllocateToTc
else a1.TC1
end as Tracking_Category_d,
case
when A1.TC1 = b2.AllocateFromTc
and A1.Date = B2.Date
then A1.Amount_New*[Percent]/100
else A1.Amount_New
end as Amountd
from olap.sampledata1 A1 , OLAP.Test B2
so mt problem is that when
i say where A1.Date <> B2.Date
its not aplying it
and that i need to breake line where
where A1.Date = B2.Date
and a1.TC1 = b2.AllocateFromTc
and after that i dont need a line that was broke
so i need to keep yelow and getd rid of red