This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!
Declare MyCursor cursor local for SELECT T0.date,T0.inQty-T0.outQty FROM INVLOG T0 INNER JOIN INV T1 ON T0.Code=T1.Code WHERE T0.date >= DATEADD(DAY,-90,GETDATE()) AND (T0.inQty-T0.outQty) IS NOT NULL AND T0.Code='ABC1' DECLARE @outdate date; SET @outdate=NULL; DECLARE @QueryResults TABLE( date date, qty int, sum int ) open MyCursor DECLARE @outdays int; SET @outdays=0; declare @fetch_status int declare @date date; declare @qty int; declare @sum int; select @fetch_status = 0 while @fetch_status = 0 begin fetch next from MyCursor into @date, @qty SET @start=@start+@qty; if @start=0 AND @outdate IS NULL BEGIN SET @outdate=@date; END IF @outdate IS NOT NULL AND @start > 0 BEGIN SET @outdays=@outdays+DATEDIFF(dd,@outdate,@date); SET @outdate=NULL; END select @fetch_status = @@fetch_status if @fetch_status <> 0 begin continue end INSERT INTO @QueryResults VALUES (@date,@qty,@start); end close MyCursor deallocate MyCursor SELECT @outdays END
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.