begin tran
update Item
set State = REPLACE(CAST(State as nvarchar(max)),'startWindow="Normal"','startWindow="Hidden"')
where Guid in
(
select SWDProgram.ProgramId
from Item
join SWDProgram on SWDProgram.[ProgramId] = Item.[Guid]
where CAST([State] AS XML).value('(/item/commandLine)[1]', 'varchar(max)') like 'swuenv%'
and not (CAST([State] AS XML).value('(/item/executionEnvironment/@startWindow)[1]', 'varchar(max)') = 'Hidden')
)
update SWDProgram
set [Start Window] = 'Hidden'
where ProgramId in
(
select SWDProgram.ProgramId
from Item
join SWDProgram on SWDProgram.[ProgramId] = Item.[Guid]
where CAST([State] AS XML).value('(/item/commandLine)[1]', 'varchar(max)') like 'swuenv%'
and not (CAST([State] AS XML).value('(/item/executionEnvironment/@startWindow)[1]', 'varchar(max)') = 'Hidden')
)
commit