Note: The preceding log excerpts are only examples. Date, time, and environmental variables may vary depending on your environment.
****BEFORE RUNNING****PLEASE TAKE A DB BACKUP****JUST IN CASE****
****BEFORE RUNNING****PLEASE TAKE A DB BACKUP****JUST IN CASE****
**********************************************************************************************************/
DECLARE @temp TABLE (id int)
BEGIN TRAN
--Show the records that are causing the problem
SELECT *
FROM [dbo].[VirtualMachineProperties]
where (PropertyName like 'VirtualMachine.Disk%.Size' or PropertyName = 'VirtualMachine.CPU.Count' or PropertyName = 'VirtualMachine.Memory.Size')
and PropertyValue like '%.%'
and ISNUMERIC(PropertyValue) = 1
order by id
--Grab the Ids of the records that are causing the problem
INSERT INTO @temp (id)
SELECT id
FROM [dbo].[VirtualMachineProperties]
where (PropertyName like 'VirtualMachine.Disk%.Size' or PropertyName = 'VirtualMachine.CPU.Count' or PropertyName = 'VirtualMachine.Memory.Size')
and PropertyValue like '%.%'
and ISNUMERIC(PropertyValue) = 1
--Update the records that are causing the problem
UPDATE [dbo].[VirtualMachineProperties]
SET PropertyValue = SUBSTRING(PropertyValue,1,CHARINDEX('.',PropertyValue)-1)
where (PropertyName like 'VirtualMachine.Disk%.Size' or PropertyName = 'VirtualMachine.CPU.Count' or PropertyName = 'VirtualMachine.Memory.Size')
and PropertyValue like '%.%'
and ISNUMERIC(PropertyValue) = 1
--Show the records that were causing the problem, but now have corrected values
SELECT vmp.*
FROM [dbo].[VirtualMachineProperties] vmp
join @temp t
on t.id = vmp.Id
order by vmp.id
/*********************************************************************************
****BEFORE UNCOMMENTING THE COMMIT ****PLEASE TAKE A DB BACKUP****JUST IN CASE****
****BEFORE UNCOMMENTING THE COMMIT ****PLEASE TAKE A DB BACKUP****JUST IN CASE****
*********************************************************************************/
--COMMIT TRAN --PLEASE TAKE A DB BACKUP FIRST, before allowing changes to be committed.
ROLLBACK TRAN --By Default Rollback the changes.