Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 November 7th, 2003, 01:32 PM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default select into non-temp table? (existing)

Thanks in advance for any help,

This is my code, it is querying a linked sql servers DB and this query works great...But I do not want the first line to drop table and I do not want to insert it into a temp table... I already have a table called ar_custcall_settlements with the proper fields ready but when I try to insert into just table name w/o # it says it already exists... I do not want to use temp tables but rather the existing table ar_custcall_settlements, and the last line (the final select) is just for testing...


________BEGIN CODE_______________________________
DROP table #ar_custcall_settlements ;

Select pa.date_entered,pa.sequence,
    pa.customer_number,pa.batch_number,
    pa.amount,
    pa.code,pa.post_date,
    pa.statement_date,pa.posted,
    pa.row_id,pa.deposit_type,
    cm.customer_name,cm.corporate_number,
    cm.sales_region_number

INTO #ar_custcall_settlements

FROM cdwacx.cdwacx.dbo.payments_and_adjustments pa,cdwacx.cdwacx.dbo.customer_master cm

WHERE (pa.date_entered BETWEEN '10/28/2003 00:00:00' AND '10/28/2003 23:59:59') AND
    (pa.customer_number = cm.customer_number) AND
    (pa.code IN('994','992')) ;

SELECT * FROM #ar_custcall_settlements ;
 
Old November 7th, 2003, 02:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

The SELECT INTO statement always creates a new table. You cannot use it to insert rows into an existing table. Use INSERT INTO <yourtable>(<columnlist>) SELECT <selectcolumnlist> FROM ...
instead.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old November 7th, 2003, 03:05 PM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default

worked perfectly, thanks!

I want to thank everyone that helps, but specifically you Jeff have assisted on many occasions... If I can ever do anything for you please let me know, [email protected] - I am an IT Manager for a telcomm company...

Nick
 
Old November 7th, 2003, 03:11 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Glad I was able to help...
Quote:
quote:
If I can ever do anything for you please let me know
I'll keep that in mind :)

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
temp table in query abdusalam Access 5 January 9th, 2008 09:28 AM
TEMP TABLE TO REAL TABLE pallone SQL Server 2000 2 June 15th, 2007 07:50 AM
Copy whole structure of table in #temp table maulik77 SQL Server 2000 2 December 21st, 2006 02:42 AM
global temp table vs.permanent table use sofya SQL Server 2000 0 December 17th, 2004 01:57 PM
#temp table object_id hortoristic SQL Server 2000 1 March 22nd, 2004 08:57 PM





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