Forum Discussion
smpa01
2 years agoCommunity Champion
Conditional row update
I have a Kusto table like this, how can I update certain fields with where condition while doing inline ingestion
id
name
city
salary
tel
1
sam
2
john
...
- Anonymous2 years ago
Hi smpa01 ,
1.Create a temporary table with the updated values:
let tempTable = datatable (id:int, name:string, city:string, salary:int, tel:string) [ 1, 'sam', 'london', 1000, null, 2, 'john', 'ny', 2000, null ];2.Merge the temporary table with the original table:
let emp = datatable (id:int, name:string, city:string, salary:int, tel:string) [ 1, 'sam', '', '', '', 2, 'john', '', '', '', 3, 'tom', '', '', '' ]; let updatedEmp = union emp, tempTable | summarize city = any(city), salary = any(salary), tel = any(tel) by id, name; .set-or-replace emp <| updatedEmpThis approach allows you to selectively update specific columns without needing to provide values for the entire row.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
2 years agoNot applicable
Hi smpa01 ,
1.Create a temporary table with the updated values:
let tempTable = datatable (id:int, name:string, city:string, salary:int, tel:string)
[
1, 'sam', 'london', 1000, null,
2, 'john', 'ny', 2000, null
];
2.Merge the temporary table with the original table:
let emp = datatable (id:int, name:string, city:string, salary:int, tel:string)
[
1, 'sam', '', '', '',
2, 'john', '', '', '',
3, 'tom', '', '', ''
];
let updatedEmp = union emp, tempTable
| summarize city = any(city), salary = any(salary), tel = any(tel) by id, name;
.set-or-replace emp <| updatedEmp
This approach allows you to selectively update specific columns without needing to provide values for the entire row.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.