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, 11:33 AM
Authorized User
 
Join Date: Jun 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to nlicata
Default Query then insert into table between 2 DBs

Hey, thanks in advance for any help.

I am querying tables called payments_and_adjustments & customer_master located in the database named cdwacx. I want to insert the data into a database that is local to the web server the query is running from, (it originates in asp for the project but now is only being tested in query analyzer). The table it is being placed in to is called ar_custcall_settlements and it is in a DB called acx_reporting. Here is what I have so far. I can't figure out how to go from DB to DB (with the SELECT INTO IN statement) that are on different servers. One in WI and one in FL. I get the following error, my code is below it. "Server: Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'IN'." Can you log into another server with in the query? Odd...

THANKS AGAIN,Nick

________BEGIN CODE______________________________________________ ________________________

Select payments_and_adjustments.date_entered,payments_and _adjustments.sequence,
    payments_and_adjustments.customer_number,payments_ and_adjustments.batch_number,
    payments_and_adjustments.amount,
    payments_and_adjustments.code,payments_and_adjustm ents.post_date,
    payments_and_adjustments.statement_date,payments_a nd_adjustments.posted,
    payments_and_adjustments.row_id,payments_and_adjus tments.deposit_type,
    customer_master.customer_name,customer_master.corp orate_number,
    customer_master.sales_region_number

INTO ar_custcall_settlements IN acx_reporting

FROM payments_and_adjustments,customer_master

WHERE (payments_and_adjustments.date_entered BETWEEN '10/28/2003 00:00:00' AND '10/28/2003 23:59:59') AND
    (payments_and_adjustments.customer_number = customer_master.customer_number) AND
    (payments_and_adjustments.code IN('994','992'))
 
Old November 7th, 2003, 11:41 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can query across databases, but not across servers with a default database configuration. You have to link the servers together.

http://www.databasejournal.com/featu...le.php/1438991

http://www.google.com/search?sourcei...linked+servers

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 7th, 2003, 11:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

The IN operator returns TRUE if the first operand is equal to any values in the list (or subquery) which is the second operand.

It has nothing to do with cross-database references.

Use the syntax:

    server.database.owner.objectname

to refer to objects (tables, views, etc) in another database, e.g.:

SELECT ... INTO acxreporting.dbo.ar_custcall_settlements ...




P.S. DO yourself a favor and save yourself a lot of typing by using a table alias, e.g.

    SELECT PA.date_entered, PA.sequence ...
        FROM payments_and_adjustments PA ...


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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert table records into another table. hewstone999 Access VBA 2 March 5th, 2008 11:01 AM
I solved insert query.now see this Update Query. [email protected] VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Can a Make Table Query produce a Linked table? kronik Access 5 May 16th, 2006 06:17 AM
Make Table query : table in Another Database marnik Access 1 March 19th, 2005 12:39 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





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