How do i split delimited string TSQL and go through a loop (while or for) and update a table column based on split values
Basically dbo.omega needs to updated for the column latest_version based on values from @source
declare @source [varchar](500)
begin
set @source = "employee:0,dept:1" # it is comma delimited string
# I want to write logic for these two updates in a single update stament by looping through @source
#UPDATE dbo.omega set latest_version = 0 where obj_name = 'employee'
#UPDATE dbo.omega set latest_version = 1 where obj_name = 'dept'
splitarr = @source.split(",")
i = 0
while(i < len(splitarr)):
UPDATE dbo.omega set latest_version = splitarr(i)
i =i+1
end