Solved

AS400 table linked to Sql Server table for import

Posted on 2004-04-27
24
588 Views
Last Modified: 2012-08-14
Hi
I have a table on the AS400 that I wish to import into my sql server database. However, I wish  to restrict the number of records I import using one of my existing sql server db tables.

Can I create a DTS routine that will import records from the AS400, but will be restricted by the sql server table?

Can this be done & if so what is the syntax, can it be completed via a DTS

Thanks in advance
Keith
0
Comment
Question by:keithjones
  • 14
  • 5
  • 3
24 Comments
 
LVL 34

Expert Comment

by:arbert
Comment Utility
Yes, but it might be very slow--you would just have to try it and see.....

Once you setup the linked server, you can base your DTS input on the query, or use a simple insert query (in the execute sql task).


Select * from as400linked.dbname.owner.table as400
where not exist (select 1 from sqltablehere where  sqltablehere.key=as400.key)


The above will get all the records from the as400 where they don't exist in the sql table....
0
 

Author Comment

by:keithjones
Comment Utility
Arbert

Right thanks for the coming back so quickly – the problem is the syntax for linking the two or writing the query.

Example

My sqlserver db is on a server called ‘srvbid02’, db called ‘court’, table ‘po_lookup’

AS400 library is ‘mmcrtlib’, table ‘new_recs’, AS400 ODBC connection ‘AS400’

Thanks
Keith
0
 

Author Comment

by:keithjones
Comment Utility
Arbert

Right thanks for the coming back so quickly – the problem is the syntax for linking the two or writing the query.

Example

My sqlserver db is on a server called  srvbid02,  db called  court ,  table po_lookup

AS400 library is  mmcrtlib ,   table new_recs , AS400 ODBC connection  AS400

Thanks
0
 

Author Comment

by:keithjones
Comment Utility
maybe my question should be, how do I link AS400 tables into my sql server db
0
 

Author Comment

by:keithjones
Comment Utility
so that I can write queries or import data based across the two systems
0
 
LVL 34

Expert Comment

by:arbert
Comment Utility
Create a linked server to the as400.

Pull up SQL Server enterprise manager, go to Security, right click on linked server, create a new linked server.

You just have to  make sure that you have Client Access (or whatever flavor of emulator you use) loaded on the sql server box....
0
 

Author Comment

by:keithjones
Comment Utility
Arbert

Right I've found the screen(brill) - tried creating a connection although I get an error

Error 7302 Could not create an instance of OLE DB provider IBMDA400
0
 

Author Comment

by:keithjones
Comment Utility
Arbert

Thanks so far, I do normally use an ODBC connection to get onto the AS400 machine (called AS400)

Keith
0
 

Author Comment

by:keithjones
Comment Utility
What is the process for setting up the link, which boxes need ticking with what....sorry for all the questions

Thanks
Keith
0
 
LVL 4

Accepted Solution

by:
rehand earned 200 total points
Comment Utility
0
 
LVL 34

Expert Comment

by:arbert
Comment Utility
If you normally use the ODBC driver for the 400, you will choose the "OLEDB driver for ODBC " when you create your connection.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:keithjones
Comment Utility
I have tried using the "OLEDB driver for ODBC " but it still doesn't seem to work
0
 

Author Comment

by:keithjones
Comment Utility
rehand

Thanks for your comments/documents links
0
 

Author Comment

by:keithjones
Comment Utility
arbert

Right I've managed to get the linked server part working & can retrieve data(see all tables on the AS400).

If I may, going back to your initial query

Select * from as400linked.dbname.owner.table as400
where not exist (select 1 from sqltablehere where  sqltablehere.key=as400.key)

Which part equates to what, currently I have a library and the AS400 connection & the table, therefore would the query just to select data from the AS400 be

Select * from AS400.mmcrtlib.pomhdr

doesn't work...if I get this bit working I'm there..

Thanks
Keith
0
 
LVL 4

Expert Comment

by:rehand
Comment Utility
You forgot a part
 
-->Select * from AS400.mmcrtlib.pomhdr

SELECT * FROM [ServerName].[DataBaseName].[Owner].[Table]

ie. SELECT * FROM AS400.mmcrtlib.dbo.pomhdr  or AS400.mmcrtlib..pomhdr
0
 

Author Comment

by:keithjones
Comment Utility
rehand

I tried

Select * from
AS400.MMCRTLIB.dbo.pomhdr

came back with the following error

OLE DB provider 'MSDASQL' does not contain table '"MMCRTLIB.dbo.pomhdr"'

The AS400 - I have linked onto it & named the the link AS400, the same as the odbc connection.....the actual AS400 server is called COURTSUK

Thanks
0
 
LVL 4

Expert Comment

by:rehand
Comment Utility
did you set the default db on the linked server?
0
 
LVL 34

Expert Comment

by:arbert
Comment Utility
dbo is SQL Server syntax for database owner--this won't work for the as400.
0
 

Author Comment

by:keithjones
Comment Utility
rehand

default db ?

arbert
I assume the dbo bit I leave out then ?

Thanks to both
0
 
LVL 34

Assisted Solution

by:arbert
arbert earned 200 total points
Comment Utility
Ya, I believe the owner equates to the catalog on the 400
0
 

Author Comment

by:keithjones
Comment Utility
arbert

sorry - tell I know zip, do you mean the catalog is the library?
0
 

Author Comment

by:keithjones
Comment Utility
Thanks to both - they recommend spliting the points
Kind regards
Keith
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now