How to update priority level from A1 to A4 Based on source Type Distributor and Source Code ?
I work on SQL Server 2012 I face issue I can't update Priority level From A1 to A4
Based Source Code And Source Type Distributor
SO I need to make query do update cases as below
update m set PriorityLevel = 'A1' from #NotMappedSource
Where distinct source type=3 and source type Distributor
have distinct source name bigger than 1
and this will be A1 for priority level
update m set PriorityLevel = 'A2' from #NotMappedSource
Where distinct source type=3 and source type Distributor
have distinct source name = 1
and this will be A2 for priority level
update m set PriorityLevel = 'A3' from #NotMappedSource
Where distinct source type=2 and source type Distributor or not
and NOT have source name is 0 for Distributor
and this will be A3 for priority level
update m set PriorityLevel = 'A4' from #NotMappedSource
Where distinct source type=1 and source type is Distributor or not
and source name is 0 for Distributor
and this will be A3 for priority level
create table #NotMappedSource
(
SourceCode int,
SourceType nvarchar(50),
SourceName nvarchar(50),
PriorityLevel nvarchar(10)
)
insert into #NotMappedSource(SourceCode,SourceType,SourceName,PriorityLevel)
values
(1300,'Distributor','Z1Source',NULL),
(1300,'Distributor','Z2Source',NULL),
(1300,'Supplier','Z2Source',NULL),
(1300,'Aggregator','Z3Source',NULL),
(1400,'Distributor','Z1Source',NULL),
(1400,'Supplier','Z1Source',NULL),
(1400,'Aggregator','Z1Source',NULL),
(1500,'Supplier','Z2Source',NULL),
(1500,'Aggregator','Z2Source',NULL),
(1550,'Supplier','Z2Source',NULL),
(1550,'Distributor',NULL,NULL),
(1600,'Supplier','Z3Source',NULL),
(1800,'Aggregator','Z2Source',NULL),
(1900,'Distributor',NULL,NULL)
Expected Result
SourceCode SourceType SourceName PriorityLevel
1300 Distributor Z1Source A1
1300 Distributor Z2Source A1
1300 Supplier Z2Source A1
1300 Aggregator Z3Source A1
1400 Distributor Z1Source A2
1400 Supplier Z1Source A2
1400 Aggregator Z1Source A2
1500 Supplier Z2Source A3
1500 Aggregator Z2Source A3
1550 Supplier Z2Source A3
1550 Distributor NULL A3
1600 Supplier Z3Source A4
1800 Aggregator Z2Source A4
1900 Distributor NULL A4
for more details