Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MY FOR IS LOOPING

Status
Not open for further replies.

gsc123

Programmer
Jan 24, 2008
197
Anyone tell me whats wrong with this code>? i = 14

rs2.Open connstring
for j = 1 to i
rs2.Execute(sqlAdd)
next
rs2.Close
 
The sql query is this -- do I need a where clause to make it only add one row?

INSERT INTO tablename ( Site, Format, [Currency], Title, SubtitleText, [Custom Label], Description, [Category 1], [Category 2], [Store Category], [Store Category 2], PicURL, Quantity, LotSize, Duration, [Starting Price], [Reserve Price], [BIN Price], [Private Auction], [Counter], [Buyer pays shipping], [Payment Instructions], [Specifying Shipping Costs], [Insurance Option], [Insurance Amount], [Sales Tax Amount], [Sales Tax State], [Apply tax to total], [Accept PayPal], [PayPal Email Address], [Accept MO Cashiers], [Accept Personal Check], [Accept Visa/Mastercard], [Accept AmEx], [Accept Discover], [Accept Payment Other], [Accept Payment Other Online], [Accept COD], [COD PrePay Delivery], [Postal Transfer], [Payment See Description], [Accept Money Xfer], CCAccepted, CashOnPickupAccepted, MoneyXferAccepted, MoneyXferAcceptedinCheckout, [Ship-To Option], Escrow, BuyerPaysFixed, [Location - City/State], [Location - Country], [Title Bar Image], Gallery1Gallery, [Gallery Featured], [Gallery URL], PicInDesc, PhotoOneRadio, PhotoOneURL, Gallery2GalleryPlus, Bold, MotorsGermanySearchable, Border, LEHighlight, [Featured Plus], [Home Page Featured], [Subtitle in search results], [Gift Icon], DepositType, DepositAmount, ShippingRate, ShippingCarrier, ShippingType, ShippingPackage, ShippingIrregular, ShippingWeightUnit, WeightMajor, WeightMinor, MeasurementUnit, PackageDimension, ShipFromZipCode, PackagingHandlingCosts, [Year], MakeCode, ModelCode, EngineCode, ThemeId, LayoutId, AutoPay, [Apply Multi-item Shipping Discount], Attributes, [Package Length], [Package Width], [Package Depth], ShippingServiceOptions, VATPercent, ProductID, UseStockPhotoURLAsGallery, IncludeStockPhotoURL, IncludeProductInfo, [UniqueIdentifier], GiftIconGiftWrap, GiftIconGiftExpressShipping, GiftIconGiftShipToRecipient, InternationalShippingServiceOptions, [Ship-To Locations], Zip, NowAndNew, [BuyerRequirements/LinkedPayPalAccount], PMPaisaPayAccepted, PaisaPayEscrowEMI, LEProPackBundle, BestOfferEnabled, [LiveAuctionDetails/LotNumber], [LiveAuctionDetails/SellerSalesNumber], [LiveAuctionDetails/LowEstimate], [LiveAuctionDetails/HighEstimate], [LiveAuctionDetails/eBayBatchNumber], [LiveAuctionDetails/eBayItemInBatch], [LiveAuctionDetails/ScheduleID], [LiveAuctionDetails/UserCatalogID], ItemExportedImages, PhotoDisplayType, TaxTable, LoanCheck, CashInPerson, HoursToDeposit, DaysToFullPayment, UserHostedOptimizePictureWellBitmap, BuyerResponsibleForShipping, GetItFast, DispatchTimeMax, [DigitalDeliveryDetails/Requirements], [DigitalDeliveryDetails/Method], [DigitalDeliveryDetails/Instructions], [DigitalDeliveryDetails/URL], CharityID, CharityName, DonationPercentage, AutoDecline, [ListingDetails/MinimumBestOfferPrice], [ListingDetails/MinimumBestOfferMessage], LEValuePackBundle, LEProPackPlusBundle, LEBasicUpgradePackBundle, LocalOnlyChk, [ListingDetails/LocalListingDistance], SkypeChat, SkypeVoice, SkypeName, ContactPrimaryPhone, ContactSecondaryPhone, LocationInfo, [ExtendedSellerContactDetails/ClassifiedAdContactByEmailEnabled], ppl_PhoneEnabled, [BuyerRequirements/ShipToRegistrationCountry], [BuyerRequirements/ZeroFeedbackScore], [BuyerRequirements/MinimumFeedbackScore], [BuyerRequirements/MaximumUnpaidItemStrikes], [BuyerRequirements/MaximumItemRequirements/MaximumItemCount], [BuyerRequirements/MaximumItemRequirements/MinimumFeedbackScore], [BuyerRequirements/VerifiedUserRequirements/VerifiedUser], [BuyerRequirements/VerifiedUserRequirements/MinimumFeedbackScore], DisableBuyerRequirements, [Domestic Insurance Option], [Domestic Insurance Amount], InternationalShippingType, InternationalPackagingHandlingCosts, [ProStores Name], [ProStores Enabled], [Domestic Profile Discount], [International Profile Discount], [Apply Profile Domestic], [Apply Profile International], SellerTags, AutoAccept, [ListingDetails/BestOfferAutoAcceptPrice] ) SELECT tablename.Site, tablename.Format, tablename.Currency, tablename.Title, tablename.SubtitleText, tablename.[Custom Label], tablename.Description, tablename.[Category 1], tablename.[Category 2], tablename.[Store Category], tablename.[Store Category 2], tablename.PicURL, tablename.Quantity, tablename.LotSize, tablename.Duration, tablename.[Starting Price], tablename.[Reserve Price], tablename.[BIN Price], tablename.[Private Auction], tablename.Counter, tablename.[Buyer pays shipping], tablename.[Payment Instructions], tablename.[Specifying Shipping Costs], tablename.[Insurance Option], tablename.[Insurance Amount], tablename.[Sales Tax Amount], tablename.[Sales Tax State], tablename.[Apply tax to total], tablename.[Accept PayPal], tablename.[PayPal Email Address], tablename.[Accept MO Cashiers], tablename.[Accept Personal Check], tablename.[Accept Visa/Mastercard], tablename.[Accept AmEx], tablename.[Accept Discover], tablename.[Accept Payment Other], tablename.[Accept Payment Other Online], tablename.[Accept COD], tablename.[COD PrePay Delivery], tablename.[Postal Transfer], tablename.[Payment See Description], tablename.[Accept Money Xfer], tablename.CCAccepted, tablename.CashOnPickupAccepted, tablename.MoneyXferAccepted, tablename.MoneyXferAcceptedinCheckout, tablename.[Ship-To Option], tablename.Escrow, tablename.BuyerPaysFixed, tablename.[Location - City/State], tablename.[Location - Country], tablename.[Title Bar Image], tablename.Gallery1Gallery, tablename.[Gallery Featured], tablename.[Gallery URL], tablename.PicInDesc, tablename.PhotoOneRadio, tablename.PhotoOneURL, tablename.Gallery2GalleryPlus, tablename.Bold, tablename.MotorsGermanySearchable, tablename.Border, tablename.LEHighlight, tablename.[Featured Plus], tablename.[Home Page Featured], tablename.[Subtitle in search results], tablename.[Gift Icon], tablename.DepositType, tablename.DepositAmount, tablename.ShippingRate, tablename.ShippingCarrier, tablename.ShippingType, tablename.ShippingPackage, tablename.ShippingIrregular, tablename.ShippingWeightUnit, tablename.WeightMajor, tablename.WeightMinor, tablename.MeasurementUnit, tablename.PackageDimension, tablename.ShipFromZipCode, tablename.PackagingHandlingCosts, tablename.Year, tablename.MakeCode, tablename.ModelCode, tablename.EngineCode, tablename.ThemeId, tablename.LayoutId, tablename.AutoPay, tablename.[Apply Multi-item Shipping Discount], tablename.Attributes, tablename.[Package Length], tablename.[Package Width], tablename.[Package Depth], tablename.ShippingServiceOptions, tablename.VATPercent, tablename.ProductID, tablename.UseStockPhotoURLAsGallery, tablename.IncludeStockPhotoURL, tablename.IncludeProductInfo, tablename.UniqueIdentifier, tablename.GiftIconGiftWrap, tablename.GiftIconGiftExpressShipping, tablename.GiftIconGiftShipToRecipient, tablename.InternationalShippingServiceOptions, tablename.[Ship-To Locations], tablename.Zip, tablename.NowAndNew, tablename.[BuyerRequirements/LinkedPayPalAccount], tablename.PMPaisaPayAccepted, tablename.PaisaPayEscrowEMI, tablename.LEProPackBundle, tablename.BestOfferEnabled, tablename.[LiveAuctionDetails/LotNumber], tablename.[LiveAuctionDetails/SellerSalesNumber], tablename.[LiveAuctionDetails/LowEstimate], tablename.[LiveAuctionDetails/HighEstimate], tablename.[LiveAuctionDetails/eBayBatchNumber], tablename.[LiveAuctionDetails/eBayItemInBatch], tablename.[LiveAuctionDetails/ScheduleID], tablename.[LiveAuctionDetails/UserCatalogID], tablename.ItemExportedImages, tablename.PhotoDisplayType, tablename.TaxTable, tablename.LoanCheck, tablename.CashInPerson, tablename.HoursToDeposit, tablename.DaysToFullPayment, tablename.UserHostedOptimizePictureWellBitmap, tablename.BuyerResponsibleForShipping, tablename.GetItFast, tablename.DispatchTimeMax, tablename.[DigitalDeliveryDetails/Requirements], tablename.[DigitalDeliveryDetails/Method], tablename.[DigitalDeliveryDetails/Instructions], tablename.[DigitalDeliveryDetails/URL], tablename.CharityID, tablename.CharityName, tablename.DonationPercentage, tablename.AutoDecline, tablename.[ListingDetails/MinimumBestOfferPrice], tablename.[ListingDetails/MinimumBestOfferMessage], tablename.LEValuePackBundle, tablename.LEProPackPlusBundle, tablename.LEBasicUpgradePackBundle, tablename.LocalOnlyChk, tablename.[ListingDetails/LocalListingDistance], tablename.SkypeChat, tablename.SkypeVoice, tablename.SkypeName, tablename.ContactPrimaryPhone, tablename.ContactSecondaryPhone, tablename.LocationInfo, tablename.[ExtendedSellerContactDetails/ClassifiedAdContactByEmailEnabled], tablename.ppl_PhoneEnabled, tablename.[BuyerRequirements/ShipToRegistrationCountry], tablename.[BuyerRequirements/ZeroFeedbackScore], tablename.[BuyerRequirements/MinimumFeedbackScore], tablename.[BuyerRequirements/MaximumUnpaidItemStrikes], tablename.[BuyerRequirements/MaximumItemRequirements/MaximumItemCount], tablename.[BuyerRequirements/MaximumItemRequirements/MinimumFeedbackScore], tablename.[BuyerRequirements/VerifiedUserRequirements/VerifiedUser], tablename.[BuyerRequirements/VerifiedUserRequirements/MinimumFeedbackScore], tablename.DisableBuyerRequirements, tablename.[Domestic Insurance Option], tablename.[Domestic Insurance Amount], tablename.InternationalShippingType, tablename.InternationalPackagingHandlingCosts, tablename.[ProStores Name], tablename.[ProStores Enabled], tablename.[Domestic Profile Discount], tablename.[International Profile Discount], tablename.[Apply Profile Domestic], tablename.[Apply Profile International], tablename.SellerTags, tablename.AutoAccept, tablename.[ListingDetails/BestOfferAutoAcceptPrice] FROM tablename
 
Found out I needed to add counter but still adding 128 rows instead of 14

rs2.Open connstring
for j = 1 to i
rs2.Execute(sqlAdd)
j = j + 1
next
rs2.Close
 
>>Found out I needed to add counter but still adding 128 rows instead of 14


Where is i set and what is its value? If you only want 14 rows added and i equals 128 you might get a few more rows than you want.
 
i is 14 - whats happenning? i thought j being zero add my counter j = j +1 would then equal i which is 14 but no 127
 
So why response.write on j give me 14? but i add the excute and i get 128?
 
i think there are some issues with your "insert". first of all, i don't see a VALUES( clause. this may be your version of sql that accepts a SELECT FROM ANOTHER TABLE. secondly, you don't have a WHERE in your SELECT statement, which means it will select all the rows from your second table. thirdly, your insert and select from are the same table. i thought a model for your sql should look like this:
INSERT INTO TABLE1 (FIELD1, FIELD2, FIELD3)
VALUES (SELECT T2.FIELD1, T2.FIELD2, T2.FIELD3 FROM TABLE2 T2 WHERE SOME SOME_FIELD = SOMETHING)
 
Like wvdba said... it needs be values
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top