Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
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
 
Old April 28th, 2004, 02:33 PM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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 ?
 
Old April 28th, 2004, 09:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old April 28th, 2004, 11:57 PM
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Skipmeok Send a message via MSN to Skipmeok
Default

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
 
Old April 29th, 2004, 07:43 AM
Authorized User
 
Join Date: Dec 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 ')'.


 
Old April 29th, 2004, 08:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

which one did you use to get that error? there were many posted here.

-Vijay G





Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is wrong of my alert statement? Edward King Javascript How-To 1 May 28th, 2005 05:12 AM
What is wrong with this insert statement? method SQL Server 2000 13 April 27th, 2005 11:46 PM
Where am I going wrong ? fredb23 Classic ASP Databases 3 August 10th, 2004 04:56 AM
What's wrong with this SQL Statement dc925 ADO.NET 4 January 23rd, 2004 11:27 AM
What's wrong with my SQL statement? kaz VS.NET 2002/2003 1 December 11th, 2003 09:21 AM





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