15,883,883 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by susanna.floora (Top 3 by date)
susanna.floora
27-Aug-13 9:07am
View
Deleted
i tried using sql cursor it works for single lot qty. i dont know how to do for multiple Lot qty.I'll post my sql query
declare @Custorders table ( ItemSize int,Product varchar(20),Qty INT, lotQty int)
insert into @Custorders select '8','Addidas Shoe',30,25
union all
select '9','Addidas Shoe',15,25
union all
select '10','Addidas Shoe',50,25
union all
select '7','Puma Shoe',40,30
union all
select '8','Puma Shoe',60,30
declare @Lot table (LotNo varchar(20),Seq int,ItemSize int,Product varchar(20),Qty int)
declare @Item varchar(20),@Product varchar(20),@Qty INT
declare @lno int
set @lno = 0
declare @seq int
set @seq = 1
-- Declare and set the cursor
declare qtycursor cursor for
select ItemSize
,Product
,Qty
from @Custorders
declare @olq INT
SET @olq=25
declare @qty_left int
set @qty_left = @olq
open qtycursor
fetch next from qtycursor into @Item, @Product, @Qty
while @@fetch_status = 0
begin
while @Qty <> 0
begin
if @Qty < @qty_left
begin
insert into @Lot
select '100'+CAST(@lno as varchar), @seq, @Item, @Product, @Qty
set @seq = @seq + 1
set @qty_left = @qty_left - @Qty
set @Qty = 0
end
else
begin
insert into @Lot
select '100'+CAST(@lno as varchar), @seq, @Item, @Product, @qty_left
set @Qty = @Qty - @qty_left
if @Qty > 0
begin
set @seq = 1
end
set @lno = @lno + 1
set @qty_left = @olq
end
end
fetch next from qtycursor into @Item, @Product, @Qty
end
close qtycursor
deallocate qtycursor
SELECT LotNo [Lot No.], Seq [Sl. No.], Product, ItemSize [Size], Qty from @Lot
susanna.floora
27-Aug-13 8:31am
View
Deleted
pls help me to achieve the result.
susanna.floora
27-Aug-13 8:29am
View
Deleted
i tried using sql cursor it works for single lot qty. i dont know how to do for multiple Lot qty.I'll post my query
declare @Custorders table
( ItemSize int,
Product varchar(20),
Qty INT, lotQty int)
insert into @Custorders
select '8','Addidas Shoe',30,25
union all
select '9','Addidas Shoe',15,25
union all
select '10','Addidas Shoe',50,25
union all
select '7','Puma Shoe',40,30
union all
select '8','Puma Shoe',60,30
declare @Lot table
(
LotNo varchar(20),
Seq int,
ItemSize int,
Product varchar(20),
Qty int)
declare @Item varchar(20)
,@Product varchar(20)
,@Qty INT
declare @lno int
set @lno = 0
declare @seq int
set @seq = 1
-- Declare and set the cursor
declare qtycursor cursor for
select ItemSize
,Product
,Qty
from @Custorders
declare @olq INT
SET @olq=25
declare @qty_left int
set @qty_left = @olq
open qtycursor
fetch next from qtycursor into @Item, @Product, @Qty
while @@fetch_status = 0
begin
while @Qty <> 0
begin
if @Qty < @qty_left
begin
insert into @Lot
select '100'+CAST(@lno as varchar), @seq, @Item, @Product, @Qty
set @seq = @seq + 1
set @qty_left = @qty_left - @Qty
set @Qty = 0
end
else
begin
insert into @Lot
select '100'+CAST(@lno as varchar), @seq, @Item, @Product, @qty_left
set @Qty = @Qty - @qty_left
if @Qty > 0
begin
set @seq = 1
end
set @lno = @lno + 1
set @qty_left = @olq
end
end
fetch next from qtycursor into @Item, @Product, @Qty
end
close qtycursor
deallocate qtycursor
SELECT LotNo [Lot No.], Seq [Sl. No.], Product, ItemSize [Size], Qty from @Lot