IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE
	TABLE_NAME = 'publ_SubjectManagement' AND
	COLUMN_NAME = 'Subjects_SubjectDetails_SubjectUniqueName')
BEGIN

ALTER TABLE [dbo].[publ_SubjectManagement]
ADD [Subjects_SubjectDetails_SubjectUniqueName] [varchar](MAX) NULL;

UPDATE [dbo].[publ_SubjectManagement]
SET Subjects_SubjectDetails_SubjectUniqueName = 
CONCAT(Subjects_SubjectDetails_SubjectName, ' (', Subjects_SubjectDetails_SubjectCode, ')')
WHERE Subjects_SubjectDetails_SubjectUniqueName IS NULL;

END;

--rename in qt
EXEC sp_rename 'qt_SubjectManagement.Subjects_SubjectDetails_ClusterLevel', 'Subjects_SubjectDetails_Level', 'COLUMN';

--rename in publ
EXEC sp_rename 'publ_SubjectManagement.Subjects_SubjectDetails_ClusterLevel', 'Subjects_SubjectDetails_Level', 'COLUMN';

--rename field
UPDATE pal_SurfaceField
SET surfaceFieldName = 'Subjects_SubjectDetails_Level',
surfaceFieldDisplay = 'Level',
lookupCategory = (select recId from pal_SurfaceLookupCategory
where lookupCategory = 'Levels'),
relationalFields = '',
relationalValues = '',
relationalOrderBy = '',
relationalObject = '',
relationalWhere = ''
WHERE surfaceFieldName = 'Subjects_SubjectDetails_ClusterLevel';
