Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 15th, 2003, 05:52 AM
JohnHalsall JohnHalsall is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 JohnHalsall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to JohnHalsall
Moving data from one SQL table to another

Hi,
I am new to using SQL and I wonder if someone could give me a bit of assistance.

I need to be able to move records from one SQL table to another, but I also need to read the previous entry in one of the columns and increment the number by one each time I move a record over.

Can anyone help because I am completely lost.
Regards
John

Reply With Quote
  #2  
Old October 15th, 2003, 11:14 AM
m_lazor m_lazor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Luxembourg
Posts: 156 m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
You have to loop thru your result set. Either use SQL cursor or create a recordset with ADO, f.e.

Reply With Quote
  #3  
Old October 17th, 2003, 09:09 PM
Scorpions4ever Scorpions4ever is offline
Mad Rater
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 126 Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 31 m 44 sec
Reputation Power: 8
Is the number important or does it just have to be in sequence? If you just want a number in sequence, then create the column as an IDENTITY type field and don't specify the column in your insert statement. SQL Server will then automatically fill up the column for you.

Code:
CREATE TABLE tableCopy (
    column1 IDENTITY(1,1),
    column2 ....
    columnxxx
)

INSERT INTO tableCopy(
      column2,
      column3,
      ... columnxxx
) 
SELECT col2, 
             col3
             col4
FROM     tableOriginal

Notice that column1 is declared as IDENTITY, but is not specified in the INSERT statement. IDENTITY(1,1) means start the column value from 1 and increment by 1 for every row inserted. If you want to start from say 15, then you would declare it as IDENTITY(15, 1)
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Moving data from one SQL table to another


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT