Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


query between 2 servers


query between 2 servers

Author
Message
Leta_Wellman
Leta_Wellman
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 20
Hi everyone!
I'm self-taught in SQL, so my knowledge is fragmented, but I'm not a complete novice.
I'm migrating an Access db to SQL2005 (that part went well) and now I'm trying to retool all the queries that were in the Access db. One of the original Access "make-table" queries used linked tables from another server.
Now, the server where my "new" SQL db resides already has a link to the other database. How would I change the Access SQL statement (that knows where the linked tables are located) to work in my new SQL db? there are 3 tables linked from the other server/db.
Here's the Access code (and I apologize in advance if I didn't link it correctly):
SELECT admin_lookup_contract.contract_id, admin_lookup_contract.contract_name, admin_lookup_contract.contract_eff_date, admin_lookup_contract.contract_exp_date, admin_lookup_program_line.program_line_desc, admin_lookup_vendor.vendor_name, admin_lookup_contract.source_set_related_contracts INTO CAMS_Snapshot
FROM (admin_lookup_contract INNER JOIN admin_lookup_program_line ON admin_lookup_contract.program_line_id = admin_lookup_program_line.program_line_id) INNER JOIN admin_lookup_vendor ON admin_lookup_contract.vendor_key = admin_lookup_vendor.vendor_key
WHERE (((admin_lookup_contract.contract_exp_date)>Date()+30));


Thanks in advance for any help for this not-so-newbie!
Leta
Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14942 Visits: 38940
this is creating a table dynamically, i think; or what access might call a query?

I'm weak on Access formatting:
this is what i'm talking about:

INTO
CAMS_Snapshot


this is your query reformatted for readability:

SELECT
admin_lookup_contract.contract_id,
admin_lookup_contract.contract_name,
admin_lookup_contract.contract_eff_date,
admin_lookup_contract.contract_exp_date,
admin_lookup_program_line.program_line_desc,
admin_lookup_vendor.vendor_name,
admin_lookup_contract.source_set_related_contracts
INTO
CAMS_Snapshot
FROM (admin_lookup_contract
INNER JOIN admin_lookup_program_line
ON admin_lookup_contract.program_line_id = admin_lookup_program_line.program_line_id)
INNER JOIN admin_lookup_vendor
ON admin_lookup_contract.vendor_key = admin_lookup_vendor.vendor_key
WHERE (( ( admin_lookup_contract.contract_exp_date ) > DATE() + 30 ));



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Leta_Wellman
Leta_Wellman
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 20
That's correct. The "INTO CAMSSnapshot" creates a table in Access.
And I want to replicate that in SQL as well.
I realize that I will have to delete the table in my new sql db each time just prior to running this query. and, no, I don't want an "update" to the SQL table, as the other db has very dynamic data that changes, if not daily, then at least monthly.
And, also, sorry about the double-post earlier, my system locked up and I accidentally posted twice.
n79799
n79799
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 122
Hi am new to this forum but found the question intersting....so trying.... :-)

From your latest response, it seemd like you want to create some kind of a stg/tmp table where you get the results as a parking spot and do rpocessing on that. The next day, again clean the table and get fresh data.
For that, you need to create an sp where first you truncate / delete your table and then get the fresh data in.
So everyday, the workflow will be.....truncate data and then data in again.

But from your first question it seemed you had a linked tables(in the access world) and that your new sql db also has a linked server setup. In that case the syntax to access tables across a linked server is as follows :
[linkedserver].[dbname].[ownernm].[tablenm]

Hope this helps

Regards
Leta_Wellman
Leta_Wellman
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 20
After digging in various places on the 'Net, I found what I wanted.
For the sake of anyone else who may be still learning like myself, here's the main portion of what worked for me:
use DATABASENAME
drop table newtable
select * into DATABASENAME.dbo. newtable
from openquery(connecteddbname,'
SELECT table1.field1,table1.field2')


there was actually more than that, as my code required two other tables, and their joins AND a delimiter of a date field of the equivalent of "today()+30"
Hopefully, the italics help highlight the fields that apply to individual db's/tables/fields.
Hope this helps someone else.

As a side note, I've come back to this forum and browsed for solutions to other questions as I've been migrating this Access program, and I have to say I HAVE found some of what I've been needing here in this forum.
Thank you to the replies that actually triggered other ideas that led to the solution.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search