

CREATE PROCEDURE [dbo].[API_WmsSpisSync]	
AS 
BEGIN

  declare @WmsDocId int;

DECLARE Doc_Cursor CURSOR FOR	 
select  Id  from dbo.ApiWmsDocuments where Direction = 11 and StateId=2 and DepartamentId<>0
  --select * from dbo.Features where Name='WMS_Niegeneruj' and ParentType='DokHandlowe'
OPEN Doc_Cursor;
FETCH NEXT FROM Doc_Cursor INTO @WmsDocId
WHILE @@FETCH_STATUS = 0
  BEGIN
	  exec [dbo].[API_WMSWmDokSpisCreate] @WmsDocId   ;
	  FETCH NEXT FROM Doc_Cursor INTO @WmsDocId;
   END;
CLOSE Doc_Cursor;
DEALLOCATE Doc_Cursor;

END
  
  