AS400 table linked to Sql Server table for import

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
keithjonesAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
arbertCommented:
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
 
keithjonesAuthor Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
keithjonesAuthor Commented:
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
 
keithjonesAuthor Commented:
maybe my question should be, how do I link AS400 tables into my sql server db
0
 
keithjonesAuthor Commented:
so that I can write queries or import data based across the two systems
0
 
arbertCommented:
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
 
keithjonesAuthor Commented:
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
 
keithjonesAuthor Commented:
Arbert

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

Keith
0
 
keithjonesAuthor Commented:
What is the process for setting up the link, which boxes need ticking with what....sorry for all the questions

Thanks
Keith
0
 
arbertCommented:
If you normally use the ODBC driver for the 400, you will choose the "OLEDB driver for ODBC " when you create your connection.
0
 
keithjonesAuthor Commented:
I have tried using the "OLEDB driver for ODBC " but it still doesn't seem to work
0
 
keithjonesAuthor Commented:
rehand

Thanks for your comments/documents links
0
 
keithjonesAuthor Commented:
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
 
rehandCommented:
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
 
keithjonesAuthor Commented:
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
 
rehandCommented:
did you set the default db on the linked server?
0
 
arbertCommented:
dbo is SQL Server syntax for database owner--this won't work for the as400.
0
 
keithjonesAuthor Commented:
rehand

default db ?

arbert
I assume the dbo bit I leave out then ?

Thanks to both
0
 
arbertConnect With a Mentor Commented:
Ya, I believe the owner equates to the catalog on the 400
0
 
keithjonesAuthor Commented:
arbert

sorry - tell I know zip, do you mean the catalog is the library?
0
 
keithjonesAuthor Commented:
Thanks to both - they recommend spliting the points
Kind regards
Keith
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.