Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2005, 03:05 PM
Authorized User
 
Join Date: Jan 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default insert into new table from recordset

I am trying to retrieve info from one table and then put it into another table...I can retrieve the info just fine I'm just having trouble putting it into the new table...

code is below.....

deaID=request("deaID")
region=request("region")

sql = "SELECT RegionCodes.zipcode FROM RegionCodes WHERE RegionName='" & region & "'"

'debugging code
Response.Write "DEBUG: SQL is " & sql & "<BR>"


set getregioncodes = conn.execute(sql)

'Response.Write DebugRs(getregioncodes)
If not getregioncodes.eof then

        Do while not getregioncodes.eof
            For each zipcode in getregioncodes.zipcode '<----------REPLACE WITH CORRECT NAME OF CHECKBOXES
              sql2 = "INSERT INTO NewDealercodes (deaID, zipcode) Values ('"&deaID&"','"&zipcode&"')"

            Next

            getregioncodes.MoveNext

            loop

            response.write "SQL is " & sql2 & "<BR>"
            set addzipcodes= conn.execute(sql2)


end if
__________________________________________________ ______

I know it has to do with my "zipcode" in the FOR statement. But I don't know how to define it from the recordset.


 
Old February 22nd, 2005, 03:25 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

which database are you using? If you are using SQL server then you can use stored procedure to do this
 
Old February 22nd, 2005, 03:26 PM
Authorized User
 
Join Date: Jan 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nevermind solved it myself

 
Old February 22nd, 2005, 04:01 PM
Authorized User
 
Join Date: Jan 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

New problem...it is only inserting 1 value into the new table...what am I doing wrong?


here is the code again

deaID=request("deaID")
region=request("region")

sql = "SELECT DISTINCT RegionCodes.zipcode FROM RegionCodes WHERE RegionName='" & region & "'"

'debugging code
Response.Write "DEBUG: SQL is " & sql & "<BR>"


set getregioncodes = conn.execute(sql)

'Response.Write DebugRs(getregioncodes)


        Do while not getregioncodes.eof

              sql2 = "INSERT INTO NewDealercodes (deaID, dealercode) Values ('"&deaID&"','"&getregioncodes("zipcode")&"')"

            getregioncodes.MoveNext

            loop

            response.write "SQL is " & sql2 & "<BR>"
            set addzipcodes= conn.execute(sql2)


 
Old February 23rd, 2005, 05:07 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

You are creating a new insert query each time you loop, but as you execute the query outside the loop, only the last query built is getting used.

Chris






Similar Threads
Thread Thread Starter Forum Replies Last Post
Diff between Recordset.update & insert cmd mp3pm VB Databases Basics 6 September 1st, 2006 03:54 PM
INSERT INTO from a SQL Server recordset? kcassidy Access 13 March 21st, 2006 08:35 AM
Insert new Record to MIDDLE of existing recordset? PanzarPaw Classic ASP Databases 5 September 11th, 2004 07:50 AM
insert 2-D pivot table into a regular recordset ? cs001 SQL Server 2000 1 November 17th, 2003 08:16 AM
Recordset date insert in access kev_79 Access ASP 3 June 5th, 2003 12:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.