August 17, 2012 at 12:53 pm
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
August 17, 2012 at 12:58 pm
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
August 17, 2012 at 1:03 pm
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.
August 21, 2012 at 7:09 pm
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
August 21, 2012 at 9:10 pm
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.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply