ich hab das in eine Prozedur eingebaut, hoffe das hilft dir weiter
--Generic Objects generieren (nur wenn Statusmodell)
insert into nuclos.T_UD_GENERICOBJECT (INTID, DATCHANGED, STRCHANGED, DATCREATED, STRCREATED, INTVERSION)
select intid, GetDate(), 'system', GetDate(), 'system', 1
from @tbl
where intid not in (select intid from nuclos.T_UD_GENERICOBJECT) and @intid_state>0
--State Historiy generieren (nur wenn sTatusmodell)
insert into nuclos.T_UD_GO_STATEHISTORY (INTID, DATCHANGED, STRCHANGED, DATCREATED, STRCREATED, INTVERSION, INTID_T_MD_STATE, INTID_T_UD_GENERICOBJECT)
select intid, GetDate(), 'system', GetDate(), 'system', 1, @intid_state , intid
from @tbl
where intid not in (select intid from nuclos.T_UD_GO_STATEHISTORY) and @intid_state>0