cmd.exe echo %TEMP%
:beg copy "%TEMP%\DocSpec.sql" C:\ /y goto beg
select SP1.DocType, SP1.DocID, SP1.SpecItem from SMSpec SP1, SMCommonBases SB, SMSpec SP2 where SP1.DocType = 'AC' and SP2.DocType = 'AC' and SB.BaseDocType = 'AC' and SB.BaseID = SP1.DocID and SB.DocType = 'AC' and SB.ID = SP2.DocID and SP1.Article = SP2.Article and exists(select 1 from SMActs A where A.DocType = 'AC' and A.ID = SP1.DocID and A.ExecIf = 3) group by SP1.DocType, SP1.DocID, SP1.SpecItem having count(*) > 1;