Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql cursor example multiple columns

 DECLARE @OrderNo NVARCHAR(50)
       DECLARE @PoNo NVARCHAR(50)
       DECLARE @ItemNo NVARCHAR(50)
       DECLARE @BarcodeNo NVARCHAR(250)
       DECLARE @CartonNo NVARCHAR(250)
       DECLARE @Qty INT
       DECLARE @CNT INT
       DECLARE ADIDAS_CURSOR CURSOR FOR

       SELECT ORDERNUMBER,PONUMBER,ITEMLINENUMBER, Quantity, UCCNumber, CartonNumber
	   FROM [MASTER] WITH (NOLOCK)
	   WHERE HasPackingInfo = 0

       OPEN ADIDAS_CURSOR
       FETCH NEXT FROM ADIDAS_CURSOR INTO @OrderNo, @PoNo, @ItemNo, @Qty, @BarcodeNo, @CartonNo
       WHILE @@FETCH_STATUS =0
       BEGIN
             SELECT @Qty= Quantity, @BarcodeNo = BarcodeNumber, @CartonNo = CartonNumber
			 FROM Shipment_856N  WITH (NOLOCK)
             WHERE SONumber= @OrderNo AND PONumber=@PoNo AND ItemLineNumber=@ItemNo
             SET @CNT = (SELECT COUNT(*) FROM Shipment_856N  WITH (NOLOCK)
             WHERE SONumber= @OrderNo AND PONumber=@PoNo AND ItemLineNumber=@ItemNo)

             IF @CNT > 0 

             BEGIN
                 UPDATE [MASTER] SET HasPackingInfo=1, Quantity=@Qty, UCCNumber=@BarcodeNo, CartonNumber=@CartonNo
                 WHERE OrderNumber = @OrderNo AND PONumber=@PoNo AND ItemLineNumber=@ItemNo
             END

             FETCH NEXT FROM ADIDAS_CURSOR INTO @OrderNo, @PoNo, @ItemNo,  @Qty, @BarcodeNo, @CartonNo
       END

       CLOSE ADIDAS_CURSOR
       DEALLOCATE ADIDAS_CURSOR
Comment

PREVIOUS NEXT
Code Example
Sql :: truncate syntax in sql 
Sql :: sql convert 
Sql :: How To Execute SQL Select Statements 
Sql :: sql server agent not running 
Sql :: mysql Digital Ocean connection problems 
Sql :: get created time of database psql 8 
Sql :: sql random date between two dates 
Sql :: classement rang mysql 7 
Sql :: psql create usr 
Sql :: calcular edad en oracle 
Sql :: oracle lower in where clause 
Sql :: sql create table with references not primary key 
Sql :: sql query tags 
Sql :: mysql auto increment jumping 
Sql :: how to get data from 2 database 
Sql :: SQL sum column resulting from query 
Sql :: difference table 
Sql :: get similar records in sql for a special number 
Sql :: TSQL select 50 records at a time 
Sql :: oracle create job if not exists 
Sql :: declare row variable sql server 
Sql :: select distinct records in sql with maximum time desc 
Sql :: uninstall mysql centos 7 
Sql :: select from where 
Sql :: Aktor yang pernah terlibat di film bergenre Aksi di sql 
Sql :: codeigniter MySQL - Issue with SELECT & GROUP BY 
Sql :: tsql rename column name 
Sql :: union and union all 
Sql :: cast float mysql 
Sql :: sql oracle take only last results 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =