-- T_EHR_RUS_2ERNPH8TQ8
update ehr
set 
	ehr.START_DATE = 
		case 
			when ehr.[START_DATE] <> '' then try_cast(ehr.[START_DATE] as datetime)
			else null
		end,
	ehr.END_DATE = 
		case 
			when ehr.END_DATE <> '' then try_cast(ehr.END_DATE as datetime)
			else null
		end 
from EHR.T_EHR_RUS_2ERNPH8TQ8 ehr

ALTER TABLE EHR.T_EHR_RUS_2ERNPH8TQ8 ALTER COLUMN [START_DATE] datetime NULL
GO
ALTER TABLE EHR.T_EHR_RUS_2ERNPH8TQ8 ALTER COLUMN END_DATE datetime NULL
GO

-- T_EHR_RUS_2M69I03GTD
update ehr
set ehr.DATE_REGISTRATION = 
	case 
		when ehr.DATE_REGISTRATION <> '' then try_cast(ehr.DATE_REGISTRATION as datetime)
		else null
	end 
from EHR.T_EHR_RUS_2M69I03GTD ehr

ALTER TABLE EHR.T_EHR_RUS_2M69I03GTD ALTER COLUMN DATE_REGISTRATION datetime NULL
GO

-- T_EHR_RUS_EP3FVD4DUL
update ehr
set ehr.depart_liquidation_date = 
		case 
			when ehr.depart_liquidation_date <> '' then try_cast(ehr.depart_liquidation_date as datetime)
			else null
		end,
	ehr.hospital_liquidation_date = 
		case 
			when ehr.hospital_liquidation_date <> '' then try_cast(ehr.hospital_liquidation_date as datetime)
			else null
		end
from EHR.T_EHR_RUS_EP3FVD4DUL ehr

ALTER TABLE EHR.T_EHR_RUS_EP3FVD4DUL ALTER COLUMN depart_liquidation_date datetime NULL
GO
ALTER TABLE EHR.T_EHR_RUS_EP3FVD4DUL ALTER COLUMN hospital_liquidation_date datetime NULL
GO

-- T_EHR_RUS_FRV440
update ehr
set ehr.DATE_END = 
		case 
			when ehr.DATE_END <> '' then try_cast(ehr.DATE_END as datetime)
			else null
		end
from EHR.T_EHR_RUS_FRV440 ehr

ALTER TABLE EHR.T_EHR_RUS_FRV440 ALTER COLUMN DATE_END datetime NULL
GO

-- T_EHR_RUS_MDR308
update ehr
set ehr.createDate = 
		case 
			when ehr.createDate <> '' then try_cast(ehr.createDate as datetime)
			else null
		end,
	ehr.deleteDate = 
		case 
			when ehr.deleteDate <> '' then try_cast(ehr.deleteDate as datetime)
			else null
		end,
	ehr.modifyDate = 
		case 
			when ehr.modifyDate <> '' then try_cast(ehr.modifyDate as datetime)
			else null
		end
from EHR.T_EHR_RUS_MDR308 ehr

ALTER TABLE EHR.T_EHR_RUS_MDR308 ALTER COLUMN createDate datetime NULL
GO
ALTER TABLE EHR.T_EHR_RUS_MDR308 ALTER COLUMN deleteDate datetime NULL
GO
ALTER TABLE EHR.T_EHR_RUS_MDR308 ALTER COLUMN modifyDate datetime NULL
GO

-- T_EHR_RUS_SF8U7PKK0U
update ehr
set ehr.Registration_date = 
		case 
			when ehr.Registration_date <> '' then try_cast(ehr.Registration_date as datetime)
			else null
		end,
	ehr.Registration_date_end = 
		case 
			when ehr.Registration_date_end <> '' then try_cast(ehr.Registration_date_end as datetime)
			else null
		end
from EHR.T_EHR_RUS_SF8U7PKK0U ehr

ALTER TABLE EHR.T_EHR_RUS_SF8U7PKK0U ALTER COLUMN Registration_date datetime NULL
GO
ALTER TABLE EHR.T_EHR_RUS_SF8U7PKK0U ALTER COLUMN Registration_date_end datetime NULL
GO