Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
smpa01
Super User
Super User

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      
3 tom      

 

I can do the following. But by doing so, I need to provide the values for whole row; which i don't want. Also, I want to to be selective in picking columns to update

 

It does not have to be inline ingest thpough.

 

 

//KQL
.ingest inline into table emp <|
1,'sam','london','1000', null
,2,'john','ny','2000',null

//SQL equivalent
UPADTE dbo.people
SET salary = case id when 1 then 1000
                  id when 2 then 2000 END
 city = case id when 1 then 'london'
                  id when 2 then 'ny' END

 

 

 

Thank you in advance

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
v-tangjie-msft
Community Support
Community Support

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. 

View solution in original post

1 REPLY 1
v-tangjie-msft
Community Support
Community Support

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. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

Top Solution Authors
Top Kudoed Authors