Announcements
Hi Teams,
I would like to update the field of a record in table A after joining with another table B on which I want to apply Group by on its ID.
I tried to run the following code but it throws me an error "Cannot edit a record in tableA. The record has never been selected":
where select forupdate tableA group by tabAid, Dimension[5]
join tableB group by tabBid, Dimension[5]
where tableA.tabAid == tableB.tabBid && tableB.Dimension[5] != "" && tableA.Dimension[5]
{
if(tableA.Dimension[5] != lines.Dimension[5])
{
ttsbegin;
tableA.Dimension[5] = tableB.Dimension[5];
tableA.update()
ttscommit;
}
}
I think it should be caused by the usage of Group By clause on tableA but if I remove it, on the if check, the tableA.Dimension[5 is empty.
Please someone help me.
Thanks in advance.
Thanks, it works
You can do the other way around -
while select firstOnly Dimension[5] from tableB join forupdate tableA where tableA.tabAid == tableB.tabBid && tableB.Dimension[5] != "" && tableA.Dimension[5] != "" { if(tableA.Dimension[5] != lines.Dimension[5]) { ttsbegin; tableA.Dimension[5] = tableB.Dimension[5]; tableA.update() ttscommit; } }
It doesn't work because it takes more than 1 record from tableB
You can try the firstonly clause in that case and check if that works for you.
while select forupdate tableA join firstOnly Dimension[5] from tableB where tableA.tabAid == tableB.tabBid && tableB.Dimension[5] != "" && tableA.Dimension[5] != "" { if(tableA.Dimension[5] != lines.Dimension[5]) { ttsbegin; tableA.Dimension[5] = tableB.Dimension[5]; tableA.update() ttscommit; } }
Hi Gunjan,
exact, I need to update the Dimension[5] value in table A with the first matching record in table B (the first one that have same id and different initial Dimension[5])
Hi Mancio13,
In case there are multiple records in table B corresponding to a single record in tableA, do you need to update the Dimension[5] value in table A with the first matching record in table B?
Hi Gunjan,
I'm using Group by on TableB because there I have multiple records with same Dimension[5] referencing a single record from table A. I tried to delete the first Group By on tableA but then it doesn't select anything from A.
For the first statement, I made a transcription error.
Hi Mancio13,
The error is being caused by the "Group by" clause. Why are you trying to do a group by when you are trying to update the Dimension[5] value?
Also, your first statement doesn't look correct. It should be "while select" instead of 'where select"
André Arnaud de Cal...
294,135
Super User 2025 Season 1
Martin Dráb
232,871
Most Valuable Professional
nmaenpaa
101,158
Moderator