Translate

> > Barcode Print Using CURSOR , For Loop and store procedure

Barcode Print Using CURSOR , For Loop and store procedure

Posted on Tuesday, July 3, 2012 | No Comments

CREATE PROCEDURE [dbo].[sp_BarcodePrint]
    -- Add the parameters for the stored procedure here
 @ChallanNo VARCHAR(256) -- filename for backup 

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    DECLARE @QTY int
    DECLARE @Barcode VARCHAR(256)

CREATE TABLE #temp (
ChalanNo VARCHAR(256),
QTY int,
ProductName VARCHAR(256),
BrandName VARCHAR(256),
LineName VARCHAR(256),
ModelName VARCHAR(256),
ColorName VARCHAR(256),
SizeName VARCHAR(256),
Barcode VARCHAR(256),
CostPrice VARCHAR(256),
SalesPrice VARCHAR(256),
VAT decimal,
Serial VARCHAR(256) )


DECLARE db_cursor CURSOR FOR 
    SELECT        RChallan.QTY,basicSetupItem.Barcode
    FROM            RChallan INNER JOIN
                             basicSetupItem ON RChallan.ItemID = basicSetupItem.ItemID
    WHERE        (RChallan.ChalanNo = @ChallanNo)

DECLARE @Flag INT

    OPEN db_cursor 
    FETCH NEXT FROM db_cursor INTO @QTY,@Barcode
   
   
    WHILE @@FETCH_STATUS = 0
    BEGIN
        SET @Flag = 1
        WHILE (@QTY >= @Flag) 
        BEGIN 
                 
                  INSERT INTO #temp (ChalanNo,QTY,ProductName,BrandName,LineName,ModelName,ColorName,SizeName,Barcode,CostPrice,SalesPrice,VAT,Serial)
                 
                   SELECT        RChallan.ChalanNo, RChallan.QTY, vBasicSetupItem.ProductName, vBasicSetupItem.BrandName, vBasicSetupItem.LineName, vBasicSetupItem.ModelName,
                             vBasicSetupItem.ColorName, vBasicSetupItem.SizeName, vBasicSetupItem.Barcode, vBasicSetupItem.CostPrice, vBasicSetupItem.SalesPrice,
                             vBasicSetupItem.VAT,@Flag
                    FROM            RChallan INNER JOIN
                             vBasicSetupItem ON RChallan.ItemID = vBasicSetupItem.ItemID
                    WHERE        (RChallan.ChalanNo = @ChallanNo) AND (vBasicSetupItem.Barcode =@Barcode)
                   
                    SET @Flag = @Flag + 1
        END
           FETCH NEXT FROM db_cursor INTO @QTY,@Barcode 
    END 

CLOSE db_cursor 
DEALLOCATE db_cursor

select * from #temp

drop table #temp

END

Leave a Reply

Powered by Blogger.