 |
| SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Language 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
|
|
|
|

April 28th, 2004, 02:33 PM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
What's wrong with this statement ?
I'm trying to copy rows from one table to another table (one table is almost a mirror copy of the other). The code I'm using isn't working. Instead of copying data from one table to another, it appears to just make a copy of the records that match the destination table instead of the source table.
Here's the code I'm using:
insert into weekhistory (Header_ID,DayOfWeek,Hrs,Rate_ID,AcctCode,Remarks, ProfitCenter,Shift_ID,Reason_ID,StandBy,EditDate,E ditBy,AlreadyProcessed)
(select Header_ID,DayOfWeek,Hrs,Rate_IDAcctCod,Remarks,Pro fitCenter,Shift_ID,Reason_ID ,StandBy ,getdate(),'197748','Y'
from week where header_id=156719)
What am I doing wrong ?
|
|

April 28th, 2004, 09:42 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
To mirror copy a table you can just use this, but in your case, there is nothing got to be used with WHERE Clause.
Select * into NEW_TABLE from OLD_TABLE
NEW_TABLE - will now have a mirro copy of the OLD_TABLE
Cheers!
-Vijay G
|
|

April 28th, 2004, 11:57 PM
|
|
Registered User
|
|
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Does this new table already exist? If not then use this;
CREATE TABLE weekhistory AS
SELECT Header_ID, DayOfWeek, Hrs, Rate_IDAcctCod, Remarks, ProfitCenter, Shift_ID, Reason_ID, StandBy, getdate(), '197748', 'Y'
FROM week
WHERE header_id=156719;
If the table already exist and you are just adding new data to it:
INSERT INTO weekhistory (Header_ID,DayOfWeek,Hrs,Rate_ID,AcctCode,Remarks, ProfitCenter,Shift_ID,Reason_ID,StandBy,EditDate,E ditBy,AlreadyProcessed)
VALUES (SELECT der_ID, DayOfWeek, Hrs, Rate_ID, AcctCod, Remarks, ProfitCenter, Shift_ID, Reason_ID, StandBy, getdate(), '197748', 'Y'
from week where header_id=156719);
Try that...
Skipmeok
|
|

April 29th, 2004, 07:43 AM
|
|
Authorized User
|
|
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm getting a syntax error using the code you suggested.
Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'SELECT'.
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near ')'.
|
|

April 29th, 2004, 08:41 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
which one did you use to get that error? there were many posted here.
-Vijay G
|
|
 |