Hi @ahmed salah ,
As mentioned by Guoxiong, it could be better for you to provide the result of below select statement ranther than update statement.
SELECT
pck1.Value OldValueID,
pck2.Value NewValueID,
a.Name old_Value,
av.Name New_Value,
isnull('[' + t.NewReplacementType + ']','') + ' ' + isnull(t.ReplacementFeature,'') + ' ' +'(' + CASE WHEN t.ReplacementFeature='Temperature' and (CHARINDEX('(TA)',a.Name)-1 > 0) THEN LEFT(a.Name,CHARINDEX('(TA)',a.Name) - 1) ELSE a.Name END + ' ' +'to' + ' ' + av.Name + ')' DisplayonPortal
FROM #TempReplacementImporter T
INNER JOIN Z2DataCore.Parts.Nop_Part RH1 WITH(NOLOCK) on RH1.PartId=T.PartIDC
INNER JOIN Z2DataCore.Parts.Nop_FamilyParametric fmc WITH(NOLOCK) ON fmc.PartFamilyID=rh1.PartsFamilyID
INNER JOIN Z2DataCore.Parts.Nop_FamilyParametricAttribute pck1 WITH(NOLOCK) ON pck1.FamilyParametricID = fmc.FamilyParametricID AND pck1.[Key]=T.[DiffFeaturesID]
inner JOIN [dbo].[Nop_AcceptedValuesOption] a WITH(NOLOCK) ON TRY_CAST(pck1.Value AS INT) =a.AcceptedValuesOptionID
INNER JOIN Z2DataCore.Parts.Nop_Part RH2 WITH(NOLOCK) on RH2.PartId=T.PartIDX
INNER JOIN Z2DataCore.Parts.Nop_FamilyParametric fmc2 WITH(NOLOCK) ON fmc2.PartFamilyID=rh2.PartsFamilyID
INNER JOIN Z2DataCore.Parts.Nop_FamilyParametricAttribute pck2 WITH(NOLOCK) ON pck2.FamilyParametricID = fmc2.FamilyParametricID AND pck2.[Key]=T.[DiffFeaturesID]
inner JOIN [dbo].[Nop_AcceptedValuesOption] av WITH(NOLOCK) ON TRY_CAST(pck2.Value AS INT) =av.AcceptedValuesOptionID
You mentioned that you needed old value and New value from same tables so you must join with same table twice. But you used the same column from the table even though you joined same 4 tables twice. So pck1.Value would be the same as pck2.Value.
You could refer below simple example:
drop table if exists #temp
drop table if exists temp1
drop table if exists temp2
create table #temp
(id int,
OldValueID int,
NewValueID int,
old_Value varchar(100),
new_Value varchar(100),
)
insert into #temp values
(1,NULL,NULL,NULL,NULL),
(2,NULL,NULL,NULL,NULL)
create table temp1
(value int
)
insert into temp1 values
(1),
(2)
create table temp2
(
ID int,
Name varchar(100)
)
insert into temp2 values
(1,'A'),
(2,'B')
select b.value OldValueID,d.value NewValueID,c.Name old_Value,e.Name new_Value
from #temp a
inner join temp1 b on a.id=b.value
inner join temp2 c on c.ID=b.value
inner join temp1 d on a.id=d.value
inner join temp2 e on e.ID=d.value
Output:
OldValueID NewValueID old_Value new_Value
1 1 A A
2 2 B B
Above OldValueID and NewValueID are the same and old_Value and new_Value are the same too.
You could try with different columns or same column with different conditions to catch the old and new values.
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hot issues November--What can I do if my transaction log is full?--- Hot issues November
Hot issues November--How to convert Profiler trace into a SQL Server table -- Hot issues November