Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql Server Enterprise Manager

Author  Topic 

l-jeff@excite.com
Starting Member

39 Posts

Posted - 2008-05-14 : 15:09:07
I have a AS400 that I retrieved data from and imported into SQL 2000 Server. However, the data will only insert 1 time. I would like to query the AS400 every minutes to update my table on SQL server. If the data is already in my table it does not get updated. How can I get updated/changed data every 15 minutes?

HELP!!!!!

Lisa Jefferson

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-14 : 15:29:39
Put your code into a job that runs every 15 minutes. It would be fairly easy to grab just the inserts and deletes provided you have a primary key, however updates will be hard and slow.


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

l-jeff@excite.com
Starting Member

39 Posts

Posted - 2008-05-14 : 16:05:22
The job is running every 15 minutes, however, the rows are just increasing with the same information. It is not giving me new/changed/updated information. How can I just get the changed info from AS400? So instead of having 400+ records, I have 400+ records every 15 minutes and it keeps increasing. I would like to get this info real time and I'm sure there is a way. Any suggestions for me?

Lisa Jefferson
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-14 : 16:10:35
You can only get this information real-time if you do it on the AS400 side. I don't know what it has to offer in terms of replication or triggers. Is the database DB2? Can it connect to SQL Server?

Do you have a primary key on the SQL Server table? If so, you can use that for inserts and deletes. With updates, you'll need to compare every single column to check if that row changed at the source for the respective row.

Do you have a linked server setup on the SQL Server pointing to the AS400? If so, could you post a sample of how to use it so that I can show you how to do inserts and deletes.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

l-jeff@excite.com
Starting Member

39 Posts

Posted - 2008-05-14 : 16:16:48
Yes, I have a primary key on the SQL, however, I get an error message when I use the key. If I take it off, I get duplicate rows again. ---------------------------
---------------------------
The task reported failure on execution.
The statement has been terminated.
Violation of PRIMARY KEY constraint 'PK_TEST RESULTS'. Cannot insert duplicate key in object 'TEST RESULTS'.


????I'm not sure about a linked server setup on SQL Server pointing to the AS400????

Second day on SQL scripting.

Lisa Jefferson
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-14 : 16:20:25
Don't worry about the insert and delete code as we call help you with that. I'll give you tips on the update, but I won't have the time to write it.

If you aren't using a linked server, then how are you able to import the data from the AS400 into the SQL Server currently?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

l-jeff@excite.com
Starting Member

39 Posts

Posted - 2008-05-14 : 16:23:25
The connection from AS400 to SQL server was already setup for me. Second day on the job and picking up the pieces for someone else. I used the sql server import data and retrieved the data from AS400.

Lisa Jefferson
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-14 : 16:29:59
This would be easiest to handle through T-SQL rather than through DTS. If you can get your connection to the AS400 setup as a linked server or OPENQUERY (check SQL Server Books Online for information), then this is simple:

-- inserts
INSERT INTO YourTable(Column1, Column2)
SELECT Column1, Column2
FROM LinkedServerName.DatabaseName.ObjectOwner.ObjectName l (this is where I don't know what to put for AS400)
WHERE NOT EXISTS (SELECT * FROM YourTable y WHERE y.PKColumn1 = l.PKColumn1)

-- deletes
DELETE y
FROM YourTable y
WHERE NOT EXISTS (SELECT * FROM LinkedServerName.DatabaseName.ObjectOwner.ObjectName l WHERE l.PKColumn1 = y.PKColumn1)

-- updates
UPDATE y
SET Column1 = l.Column1, Column2 = l.Column2, ...
FROM YourTable y
INNER JOIN Linked... l
ON y.PKColumn1 = l.PKColumn1
WHERE l.Column1 <> y.Column1 OR l.Column2 <> y.Column2 ...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-05-14 : 16:31:13
If you must use DTS or can't get the linked server/OPENQUERY setup, then have your DTS package import the data into a staging table that has the same layout as your actual table. Then use the code above to modify your table by replacing Linked... parts with the staging table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Database maintenance routines:
http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx
Go to Top of Page

l-jeff@excite.com
Starting Member

39 Posts

Posted - 2008-05-14 : 16:52:28
I will lookup the linked server or OPENQUERY first. Thanks so much.

Lisa Jefferson
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-05-14 : 17:36:42
You want to create a linked server and a table...or Better yet (depending on the volume) copy the table over to a stage table in your database

Then do this

http://weblogs.sqlteam.com/brettk/archive/2004/04/23/1281.aspx

The other alternative is that if the table has add date/ update date on the table, grab only the effected rows

Deletes would be a Little more problematic

The idea is to take the network out of play as much as possible



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -