praveen2006
Starting Member
2 Posts |
Posted - 2011-05-18 : 03:00:47
|
Below is the CodeIND2802201114_Catalog --> Table 1 --> which as around 10000 rowsng_catalog..productcatalog2 --> Table 2 --> which as around 5 million rowsI need to check isbn is available or not, if available update in Table 2 or insert in Table 2-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --DECLARE CURProduct CURSOR FAST_FORWARD FOR select [ISBN13],Price,[Name],[Author1],[Currency],[Publisher],[BindingType] from IND2802201114_Catalog where Stock >=5 and DateModified >= convert(varchar,getdate(),101) OPEN CURProduct FETCH Next FROM CURProduct INTO @ISBN,@price,@title,@author,@curr,@publishername,@binding While @@FETCH_STATUS=0 Begin set @listPrice = round(CONVERT(money,@Price) * CONVERT(money,@US),0) /* Checking Whether The ISBN Is Available In Product Catalog Table.... */ if exists (select isbn from ng_catalog..productcatalog2 where ISBN=@ISBN) Begin /* Checking Whether The ISBN Is Available In Supplier Table.... If True - Update ISBN Into Supplier Table */ if exists (select sku from ng_catalog..suppliersku2 where sku=@ISBN and SPID=@vendorid) Begin Update ng_catalog..suppliersku2 set [List Price] = round(@listPrice,0), [Buy Price] =round((@listPrice * (100-@margin)/100),0), [Currency Value] =CONVERT(money, @price), [Currency Type] = @CurrencyType, LastModified = getdate(), [bookRsValue] =round(@listPrice,0), [Item Qty] = 1, [Item Status] = 1 where sku = @isbn and SPID=@vendorid End Else /* If The ISBN Is Not Available In Supplier Table, Control Comes Hear.... Insert ISBN Into Supplier Table */ Begin -- Select @publisherId = publisher from ng_catalog..productcatalog2 where sku=@ISBN and publisherid is not null -- Select @priority = Priority from ng_catalog..PublisherVendorPriority where PublisherId = @publisherId Insert into ng_catalog..suppliersku2(Store_id,sku,[MFR Item Code],[Buy Price],[List Price],[Item Status],[Item Qty],[Currency Value], [Currency Type],[UpdatedBy],LastModified,[BookRsValue], SpId) Values (2,@isbn,@isbn,(@listPrice * (100-@margin)/100), @listPrice,1,1, CONVERT(money, @price), @CurrencyType, 'New Supplier', getdate(), @listPrice, @vendorid) -- Print 'Supplier Insert Successfully Completed' End EndFETCH NEXT FROM CURProduct INTO @isbn,@price,@title,@author,@curr,@publishername,@bindingEnd Close CURProduct Deallocate CURProduct |
|
|