Author |
Topic |
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-16 : 04:52:40
|
hi all,how do i select all the first date in first? here's my sample data :--- Prepare sample dataDECLARE @DataList TABLE (ItemStorageID VARCHAR(2), Qty float, recvDate datetime)INSERT @DataListSELECT 'A1', 24, '2006-11-17 00:00:00.000' UNION ALLSELECT 'A4', 24, '2006-08-11 00:00:00.000' UNION ALLSELECT 'A5', 24, '2006-11-17 00:00:00.000' UNION ALLSELECT 'A2', 24, '2006-08-11 00:00:00.000' UNION ALLSELECT 'A3', 24, '2006-08-11 00:00:00.000' UNION ALLSELECT 'A6', 24, '2006-08-11 00:00:00.000' DECLARE @Data TABLE (ItemCount INT, itemQty float)INSERT @DataSELECT 4, 24SELECT dl.ItemStorageid, dl.RecvDate, dl.QtyFROM @Datalist AS dlINNER JOIN @Data AS dt ON dt.ItemQty=dl.QtyWHERE dt.ItemCount >= (SELECT COUNT(*) FROM @Datalist AS x WHERE x.Qty=dl.Qty AND x.ItemStorageID <=dl.ItemStorageID) will give meA1 2006-11-17 00:00:00.000 24.0 **** A4 2006-08-11 00:00:00.000 24.0A2 2006-08-11 00:00:00.000 24.0A3 2006-08-11 00:00:00.000 24.0when i expect it list all the first dateA1A6 2006-08-11 00:00:00.000 24.0 ****A4 2006-08-11 00:00:00.000 24.0A2 2006-08-11 00:00:00.000 24.0A3 2006-08-11 00:00:00.000 24.0thankss in advance~~~Focus on problem, not solution~~~ |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-16 : 04:54:28
|
Are you using SQL Server 2000 or SQL Server 2005?Peter LarssonHelsingborg, Sweden |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-16 : 05:04:47
|
hi peter,im using :-Microsoft SQL Enterprise ManagerMicrosoft CorporationVersion: 8.0Microsoft SQL server 2000~~~Focus on problem, not solution~~~ |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-16 : 05:20:58
|
There is no record where ItemStorageID = 'A1' and recvDate = '2006-08-11'. Then how can you expect the output you stated?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-16 : 05:21:03
|
You have to tell us the business rules.What are you trying to accomplish?Peter LarssonHelsingborg, Sweden |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-16 : 07:09:05
|
harsh,sorry wrong expected output.. i've edit that output part..A6 2006-08-11 00:00:00.000 24.0 ****A4 2006-08-11 00:00:00.000 24.0A2 2006-08-11 00:00:00.000 24.0A3 2006-08-11 00:00:00.000 24.0peter,im trying to list all the record from datalist order by date.. like the datalist record, it contains a few records on 17 oct and 11 august.. i need to list all earlier date record first.. but i couldnt order it by recvdate.. it said couldnt order inline function..~~~Focus on problem, not solution~~~ |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-16 : 07:14:42
|
[code]SELECT dl.ItemStorageid, dl.RecvDate, dl.QtyFROM @Datalist AS dlINNER JOIN @Data AS dt ON dt.ItemQty=dl.QtyWHERE dl.RecvDate = (SELECT min(RecvDate) FROM @Datalist)[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-16 : 20:48:16
|
no, i dun think so.. this will only list all the minimum date.. whereas, according to @data, i want to list 4 record in @datalist which qty=24 (ive done this),this what i need to do next : list first date in first.. so in this case, there are records in @datalist :-17 nov : 24 (A1)11 aug : 24 (A4)17 nov : 24 (A5)11 aug : 24 (A2)11 aug : 24 (A3)11 aug : 24 (A6)record in @Data4 : how many record i want to print24 : qty i must findso, i need to find 4 records wif 24 qty... problem is i want to list down earlier date first.. so according to @Datalist i will list all 4 records in 11-august first followed by records in 17 november (if still not enough), result :-11 aug : 24 (A4)11 aug : 24 (A2)11 aug : 24 (A3)11 aug : 24 (A6)so if my @Data record has 5, 24 means it want to list 5 records with qty=24, then the result will include date 17-nov becoz all records in 11 august has been list to fullfill the condition in @Data (find 5 records with qty=24)...(not all minimum date, harsh), result :-11 aug : 24 (A4)11 aug : 24 (A2)11 aug : 24 (A3)11 aug : 24 (A6)17 nov : 24 (A1)hopefully this is understandable.. besides my poor englishg.. thank u for reading :D~~~Focus on problem, not solution~~~ |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-17 : 01:39:54
|
[code]-- Do the workDECLARE @Items INT, @Qty INTSELECT @Items = ItemCount, @Qty = ItemQtyFROM @DataSET ROWCOUNT @ItemsSELECT ItemStorageID, RecvDate, QtyFROM @DatalistWHERE Qty = @QtyORDER BY RecvDate, ItemStorageIDSET ROWCOUNT 0[/code]Peter LarssonHelsingborg, Sweden |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-17 : 01:57:54
|
emm..yeayy.. there u are.. it works... but way to long to sip in to my SP.. nvm.. tq peter,~~~Focus on problem, not solution~~~ |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-17 : 02:23:53
|
quote: Originally posted by maya_zakry emm..yeayy.. there u are.. it works... but way to long to sip in to my SP.. nvm.. tq peter,
Way too long for a stored procedure?Peter LarssonHelsingborg, Sweden |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-17 : 03:04:15
|
way too long to sip in here or i dunno how to :-CREATE PROCEDURE SP_StageAutoPick( @JobID VARCHAR(12), @DocRefID VARCHAR(12), @Shipper varchar(20), @ItemID varchar(50), @CustomLotNo VARCHAR(20), @WantedValue INT)AS-- Stage the source dataCREATE TABLE #Data ( RecID INT IDENTITY(1, 1) PRIMARY KEY CLUSTERED, MaxItems INT, CurrentItems INT DEFAULT 0, FaceValue INT, BestUnder INT DEFAULT 0, BestOver INT DEFAULT 1 )-- Aggregate the source data--This execution of Sp calls the filtered data from whateva filtered Sp out there, sum by AVAQty for filtering suitable pickqtyINSERT #Data ( MaxItems, FaceValue ) EXEC SP_StageData @JobID = @JobID, @DocRefID = @DocRefID, @Shipper= @Shipper, @ItemID= @ItemID, @CustomLotNo = @CustomLotNo, @WantedValue=@Wantedvalue-- This execution of Sp calls the original data from #Data that had been sum up, to get the itemstorageid to populate the data for viewingCREATE TABLE #DataList ( ItemStorageID varchar(10), Qty float, PickNm varchar(50), recvDate datetime, ExpDate datetime )INSERT #DataList ( ItemStorageID, Qty, PickNm, RecvDate, ExpDate ) EXEC SP_StageAllData @JobID = @JobID, @DocRefID = @DocRefID, @Shipper= @Shipper, @ItemID= @ItemID, @CustomLotNo = @CustomLotNo, @WantedValue=@Wantedvalue-- Declare some control variablesDECLARE @CurrentSum INT, @BestUnder INT, @BestOver INT, @RecID INT-- If productsum is less than or equal to the wanted sum, select all items!IF (SELECT SUM(MaxItems * FaceValue) FROM #Data) <= @WantedValue BEGIN SELECT DISTINCT dl.ItemStorageId, dl.Qty AS BalQty, dl.PickNm, d.ItemID, d.DocRefID, d.CustomlotNo, d.StorageID, d.CartonID, d.WhsId, d.LocID, d.recvdate, d.ExpiryDate, r.PickType, d.RET, d.ConsignmentStock, d.NonConsignmentStock, c.ClientUDF1, c.ClientUDF2, c.ClientUDF3, c.ClientUDF4, c.ClientUDF5, c.ClientUDF6, c.ClientUDF7, c.ClientUDF8, c.ClientUDF9, c.ClientUDF10, d.RecvUDF1, d.RecvUDF2, d.RecvUDF3, d.RecvUDF4, d.RecvUDF5, d.RecvUDF6, d.RecvUDF7, d.RecvUDF8, d.RecvUDF9, d.RecvUDF10, r.Breakbulk, r.CBreakbulk, d.DocRefID, r.PickUOM FROM #DataList AS dl INNER JOIN #Data AS dt ON dt.FaceValue=dl.Qty INNER JOIN tblItemDetail d ON d.ItemStorageID = dl.ItemStorageID LEFT JOIN tblClient c ON c.ClientID=@Shipper LEFT JOIN tblItemCrossRef r On r.ClientID=@Shipper AND r.ItemID=d.ItemID WHERE dt.MaxItems >= (SELECT top 1 COUNT(*) FROM #Datalist AS x WHERE x.Qty=dl.Qty AND x.ItemStorageID <=dl.ItemStorageID order by dl.recvdate ) RETURN END-- Delete all unworkable FaceValues (more than wantedvalue)DELETEFROM #DataWHERE FaceValue > (SELECT MIN(FaceValue) FROM #Data WHERE FaceValue >= @WantedValue)-- Update MaxItems to a proper valueUPDATE #DataSET MaxItems = CASE WHEN 1 + (@WantedValue - 1) / FaceValue < MaxItems THEN 1 + (@WantedValue - 1) / FaceValue ELSE MaxItems END-- Update BestOver to a proper valueUPDATE #DataSET BestOver = MaxItems-- Initialize the control mechanismSELECT @RecID = MIN(RecID), @BestUnder = 0, @BestOver = SUM(BestOver * FaceValue)FROM #Data-- Do the loop!WHILE @RecID IS NOT NULL BEGIN -- Reset all "bits" not incremented UPDATE #Data SET CurrentItems = 0 WHERE RecID < @RecID -- Increment the current "bit" UPDATE #Data SET CurrentItems = CurrentItems + 1 WHERE RecID = @RecID -- Get the current sum SELECT @CurrentSum = SUM(CurrentItems * FaceValue) FROM #Data WHERE CurrentItems > 0 -- Stop here if the current sum is equal to the sum we want IF @CurrentSum = @WantedValue BREAK ELSE -- Update the current BestUnder if previous BestUnder is less IF @CurrentSum > @BestUnder AND @CurrentSum < @WantedValue BEGIN UPDATE #Data SET BestUnder = CurrentItems SET @BestUnder = @CurrentSum END ELSE -- Update the current BestOver if previous BestOver is more IF @CurrentSum > @WantedValue AND @CurrentSum < @BestOver BEGIN UPDATE #Data SET BestOver = CurrentItems SET @BestOver = @CurrentSum END -- Find the next proper "bit" to increment SELECT @RecID = MIN(RecID) FROM #Data WHERE CurrentItems < MaxItems ENDIF @RecID IS NULL IF @WantedValue - @BestUnder < @BestOver - @WantedValue -- If BestUnder is closer to the sum we want, choose that BEGIN --breakbulk=Y SELECT DISTINCT dl.ItemStorageId, dl.Qty AS BalQty, dl.PickNm, d.ItemID, d.DocRefID, d.CustomlotNo, d.StorageID, d.CartonID, d.WhsId, d.LocID, d.recvdate, d.ExpiryDate, r.PickType, d.RET, d.ConsignmentStock, d.NonConsignmentStock, c.ClientUDF1, c.ClientUDF2, c.ClientUDF3, c.ClientUDF4, c.ClientUDF5, c.ClientUDF6, c.ClientUDF7, c.ClientUDF8, c.ClientUDF9, c.ClientUDF10, d.RecvUDF1, d.RecvUDF2, d.RecvUDF3, d.RecvUDF4, d.RecvUDF5, d.RecvUDF6, d.RecvUDF7, d.RecvUDF8, d.RecvUDF9, d.RecvUDF10, r.Breakbulk, r.CBreakbulk, d.DocRefID, r.PickUOM --MAX(d.recvdate) AS MaxRecvdate, MIN(d.recvdate) AS MinRecvdate FROM #DataList AS dl LEFT JOIN #Data AS dt ON dt.FaceValue=dl.Qty INNER JOIN tblItemDetail d ON d.ItemStorageID = dl.ItemStorageID LEFT JOIN tblClient c ON c.ClientID=@Shipper LEFT JOIN tblItemCrossRef r On r.ClientID=@Shipper AND r.ItemID=d.ItemID WHERE dt.BestUnder > 0 AND dt.BestUnder >=(SELECT top 1 with ties COUNT(*) FROM #Datalist AS x WHERE x.Qty=dl.Qty AND x.ItemStorageID <=dl.ItemStorageID order by dl.recvdate ) RETURN END ELSE -- If BestOver is closer to the sum we want, choose that BEGIN --Breakbulk=Y SELECT DISTINCT dl.ItemStorageId, dl.Qty AS BalQty, dl.PickNm, d.ItemID, d.DocRefID, d.CustomlotNo, d.StorageID, d.CartonID, d.WhsId, d.LocID, d.recvdate, d.ExpiryDate, r.PickType, d.RET, d.ConsignmentStock, d.NonConsignmentStock, c.ClientUDF1, c.ClientUDF2, c.ClientUDF3, c.ClientUDF4, c.ClientUDF5, c.ClientUDF6, c.ClientUDF7, c.ClientUDF8, c.ClientUDF9, c.ClientUDF10, d.RecvUDF1, d.RecvUDF2, d.RecvUDF3, d.RecvUDF4, d.RecvUDF5, d.RecvUDF6, d.RecvUDF7, d.RecvUDF8, d.RecvUDF9, d.RecvUDF10, r.Breakbulk, r.CBreakbulk, d.DocRefID, r.PickUOM FROM #DataList AS dl LEFT JOIN #Data AS dt ON dt.FaceValue=dl.Qty INNER JOIN tblItemDetail d ON d.ItemStorageID = dl.ItemStorageID LEFT JOIN tblClient c ON c.ClientID=@Shipper LEFT JOIN tblItemCrossRef r On r.ClientID=@Shipper AND r.ItemID=d.ItemID WHERE dt.BestOver > 0 AND dt.BestOver >=(SELECT top 1 with ties COUNT(*) FROM #Datalist AS x WHERE x.Qty=dl.Qty AND x.ItemStorageID <=dl.ItemStorageID order by dl.recvdate ) RETURN END ELSE -- We have an exact match BEGIN --breakbulk=Y SELECT DISTINCT dl.ItemStorageId, dl.Qty AS BalQty, dl.PickNm, d.ItemID, d.DocRefID, d.CustomlotNo, d.StorageID, d.CartonID, d.WhsId, d.LocID, d.recvdate, d.ExpiryDate, r.PickType, d.RET, d.ConsignmentStock, d.NonConsignmentStock, c.ClientUDF1, c.ClientUDF2, c.ClientUDF3, c.ClientUDF4, c.ClientUDF5, c.ClientUDF6, c.ClientUDF7, c.ClientUDF8, c.ClientUDF9, c.ClientUDF10, d.RecvUDF1, d.RecvUDF2, d.RecvUDF3, d.RecvUDF4, d.RecvUDF5, d.RecvUDF6, d.RecvUDF7, d.RecvUDF8, d.RecvUDF9, d.RecvUDF10, r.Breakbulk, r.CBreakbulk, d.DocRefID, r.PickUOM --MAX(d.recvdate) AS MaxRecvdate, MIN(d.recvdate) AS MinRecvdate FROM #DataList AS dl LEFT JOIN #Data AS dt ON dt.FaceValue=dl.Qty INNER JOIN tblItemDetail d ON d.ItemStorageID = dl.ItemStorageID LEFT JOIN tblClient c ON c.ClientID=@Shipper LEFT JOIN tblItemCrossRef r On r.ClientID=@Shipper AND r.ItemID=d.ItemID WHERE dt.CurrentItems > 0 AND dt.CurrentItems >= (SELECT top 1 with ties COUNT(*) FROM #Datalist AS x WHERE x.Qty=dl.Qty AND x.ItemStorageID <=dl.ItemStorageID order by dl.recvdate ) RETURN END DROP TABLE #DataGO yeah, remember this one worked well before..the one with ur script to find combination of X, but then i have to consider the dates also.. but forget it.. maybe need another approach, i need to ask ur opinion on how do we find X records with sum(col1)=any value..from my sample @datalist, say i have param @wantedValue=50, how do i find total sum <= 50?this one surely cant work, : how?select * from @datalist where sum(Qty) <= @Wantedvalue order by recvdatethanks~~~Focus on problem, not solution~~~ |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-17 : 03:07:25
|
No, no, no....Leave that algorithm intact and use the result FROM it with the suggestion I made earlier today.Peter LarssonHelsingborg, Sweden |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-17 : 03:25:29
|
okay peter, help again,yeah forget abt the algorithm, this is different..im not sure how to use set rowcount into this.. Scenario : Find from this records(dont care how many rows), where total of Qty=72-- Prepare sample dataDECLARE @DataList TABLE (ItemStorageID VARCHAR(2), Qty float, recvDate datetime)INSERT @DataListSELECT 'A1', 24, '2006-11-17 00:00:00.000' UNION ALLSELECT 'A4', 24, '2006-08-11 00:00:00.000' UNION ALLSELECT 'A5', 24, '2006-11-17 00:00:00.000' UNION ALLSELECT 'A2', 24, '2006-08-11 00:00:00.000' UNION ALLSELECT 'A3', 24, '2006-08-11 00:00:00.000' UNION ALLSELECT 'A6', 24, '2006-08-11 00:00:00.000' HELP ME FROM HEREDeclare @Total AS INTSET @Total=72 -- Do the workSET ROWCOUNT --what to set hereSELECT ItemStorageID, RecvDate, QtyFROM @DatalistWHERE sum(QTy) <= @TotalORDER BY RecvDate, ItemStorageID SET ROWCOUNT 0 ~~~Focus on problem, not solution~~~ |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-17 : 03:34:52
|
Using my original algorithm, you will get a result ofSumType Items FaceValue------- ----- --------- 0 3 24 Are you with me?WriteINSERT #DataEXEC <Name for my original algorithm SP here> and hereafter use the code suggested in this topic, in your code AUTOPICK-- Do the workDECLARE @Items INT, @Qty INTSELECT @Items = ItemCount, @Qty = ItemQtyFROM #Data -- Formerly known as @DataSET ROWCOUNT @ItemsSELECT ItemStorageID, RecvDate, QtyFROM @DatalistWHERE Qty = @QtyORDER BY RecvDate, ItemStorageIDSET ROWCOUNT 0 Peter LarssonHelsingborg, Sweden |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-17 : 04:08:10
|
<-- cry cry cryy1.okay, i decided not to use that script nmore coz i want my combination must be MORE than my @WantedValue, and must consider dates. Previously, it pick 50 when my @WantedValue=51.. and it lists down not according to date.. ok so i drop the case2.in this new case, i want to ask how do we select record with total sum(someFloatcolumn) >= someInteger value with Order by somedatecolumn?u recommended using SET ROWCOUNT, but i dunno how.. eg : @WantedValue=36id. Qty rdate1. 18 13-aug-20062. 17 14-aug-20063. 5 14-aug-20064. 18 22-aug-2006so given @WantedValue=36, i need to find earliest records with total of column Qty >= 36 i expect to get :-id. Qty rdate1. 18 13-aug-20062. 17 14-aug-20063. 5 14-aug-2006-- Prepare sample dataDECLARE @table1 TABLE (ID INT, Qty float, recvDate datetime)INSERT @table1SELECT '1', 18, '2006-08-13 00:00:00.000' UNION ALLSELECT '2', 17, '2006-08-14 00:00:00.000' UNION ALLSELECT '3', 5, '2006-08-14 00:00:00.000' UNION ALLSELECT '4', 18, '2006-08-22 00:00:00.000' select * from @table1 ~~~Focus on problem, not solution~~~ |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-17 : 04:29:36
|
[code]-- Prepare sample dataDECLARE @Table1 TABLE (ID INT, Qty MONEY, RecvDate DATETIME)INSERT @Table1SELECT '1', 18, '2006-08-13 00:00:00.000' UNION ALLSELECT '2', 17, '2006-08-14 00:00:00.000' UNION ALLSELECT '3', 5, '2006-08-14 00:00:00.000' UNION ALLSELECT '4', 18, '2006-08-22 00:00:00.000' -- Stage the dataDECLARE @Stage TABLE (RecID INT IDENTITY(1, 1), ID INT, Qty MONEY, RecvDate DATETIME)DECLARE @WantedValue INTSET @WantedValue = 36WHILE (SELECT COALESCE(SUM(Qty), 0) FROM @Stage) < @WantedValue AND @@ROWCOUNT > 0 INSERT @Stage (ID, Qty, RecvDate) SELECT TOP 1 t1.ID, t1.Qty, t1.RecvDate FROM @Table1 AS t1 LEFT JOIN @Stage AS s ON s.ID = t1.ID WHERE s.ID IS NULL ORDER BY t1.RecvDate, t1.Qty DESCIF (SELECT COALESCE(SUM(Qty), 0) FROM @Stage) >= @WantedValue SELECT ID, Qty, RecvDate FROM @StageELSE SELECT 'No oversum available'[/code]Peter LarssonHelsingborg, Sweden |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-17 : 04:36:24
|
yeayyyyyyy... terima kasih peso means thanks hehehheeven though ive no idea how it works.. need sometime to digest~~~Focus on problem, not solution~~~ |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-17 : 04:43:02
|
cry cry cry ... it takes sometimes to run..~~~Focus on problem, not solution~~~ |
|
|
maya_zakry
Constraint Violating Yak Guru
379 Posts |
Posted - 2007-04-17 : 04:47:16
|
wow.. the new edited works double trouble triple faster~~~Focus on problem, not solution~~~ |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-17 : 04:50:35
|
Is this slow?-- Prepare sample dataDECLARE @Table1 TABLE (ID INT, Qty MONEY, RecvDate DATETIME)INSERT @Table1SELECT '1', 18, '2006-08-13 00:00:00.000' UNION ALLSELECT '2', 17, '2006-08-14 00:00:00.000' UNION ALLSELECT '3', 5, '2006-08-14 00:00:00.000' UNION ALLSELECT '4', 18, '2006-08-22 00:00:00.000' -- Initialize search parameterDECLARE @WantedValue INT, @Sum INTSELECT @WantedValue = 36, @Sum = @WantedValue-- Stage the dataDECLARE @Stage TABLE (ID INT, Qty MONEY, RecvDate DATETIME)DECLARE curStage CURSOR FORWARD_ONLY READ_ONLY FOR SELECT ID, Qty, RecvDate FROM @Table1 ORDER BY RecvDate, Qty DESCDECLARE @ID INT, @Qty MONEY, @RecvDate DATETIMEOPEN curStageFETCH NEXTFROM curStageINTO @ID, @Qty, @RecvDateWHILE @@FETCH_STATUS = 0 AND @Sum > 0 BEGIN SET @Sum = @Sum - @Qty INSERT @Stage (ID, Qty, RecvDate) SELECT @ID, @Qty, @RecvDate FETCH NEXT FROM curStage INTO @ID, @Qty, @RecvDate ENDCLOSE curStageDEALLOCATE curStage-- Show the expected outputIF @Sum <= 0 SELECT ID, Qty, RecvDate FROM @Stage ORDER BY RecvDate, Qty DESCELSE SELECT 'No oversum found' Peter LarssonHelsingborg, Sweden |
|
|
Next Page
|
|
|