IF COLUMNPROPERTY(OBJECT_ID('AKUZ.T_CARD_NOTE'), 'NeedMoSign', 'ColumnId') IS NULL
BEGIN
    ALTER TABLE AKUZ.T_CARD_NOTE 
    ADD NeedMoSign bit NULL
END
GO

UPDATE AKUZ.T_CARD_NOTE
SET NeedMoSign = 1
WHERE 
	NOT EXISTS (SELECT * FROM AKUZ.T_CARD_NOTE_SIGNATURE cns where cns.CardNote = MedicalRecordID and cns.SignType = 0 and cns.Signed = 0)
	AND EXISTS (SELECT * FROM AKUZ.T_CARD_NOTE_SIGNATURE cns2 where cns2.CardNote = MedicalRecordID and cns2.SignType = 1 and cns2.Signed = 0)