ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 275.3k

How to add mapped to in table trade codes where mapped from exist ?

Feb 1 2021 10:00 PM

I work on SQL server 2012 I face issue I can't insert mapped to into table trade codes where mapped from exist
on table trade code

so firstly I will get MapCodeTypeFrom and MapCodeValueFrom from table settings

second i will search on table tradecodes for MapCodeTypeFrom and MapCodeValueFrom

if MapCodeTypeFrom and MapCodeValueFrom exist on table trade Codes

then add MapCodeTypeTo and MapCodeValueTo for every part

that meaning every part have MapCodeTypeFrom and MapCodeValueFrom on table TradeCodes
must have MapCodeTypeTo and MapCodeValueTo

 with another meaning every part must have two rows
first row for MapCodeTypeFrom and MapCodeValueFrom
second row for MapCodeTypeTo and MapCodeValueTo

 
  1. create table #settings  
  2.  (  
  3.  MapId int,  
  4.  MapCodeTypeFrom nvarchar(50),  
  5.  MapCodeValueFrom int,  
  6.  MapCodeTypeTo nvarchar(50),  
  7.  MapCodeValueTo int  
  8.  )  
  9.  insert into #settings(MapId,MapCodeTypeFrom,MapCodeValueFrom,MapCodeTypeTo,MapCodeValueTo)  
  10.  values  
  11.  (1222,'ECCN',9910,'HTS',9920),  
  12.  (1222,'Hom',9950,'VOM',9960)  
  13.       
  14.  --DROP TABLE #TradeCodes  
  15.  create table #TradeCodes  
  16.  (  
  17.  PartId  int,  
  18.  CodeType nvarchar(50),  
  19.  Code   int,  
  20.  )  
  21.  insert into #TradeCodes(PartId,CodeType,Code)  
  22.  values  
  23.  (1334,'ECCN',9910),  
  24.  (1971,'ECCN',9910),  
  25.  (2050,'ECCN',9910),  
  26.  (3000,'VOM',9950),  
  27.  (3600,'VOM',9950),  
  28.  (3700,'VOM',9950)   
final rows must added on table trade codes that represent mapped to is :
  1. PartId CodeType Code  
  2. 1334 HTS 9920  
  3. 1971 HTS 9920  
  4. 2050 HTS 9920  
  5. 3000 VOM 9960  
  6. 3600 VOM 9960  
  7. 3700 VOM 9960  
mapped to will added in case of mapped from code type and value Exist on table trade codes 

Answers (1)