473,806 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL DTS query using WHILE Statement successfully executes (only updating 200 of 1494 records)

I am running a DTS Package.
I have a temp table with 1494 records. I am inserting a 'Y' or
'N'into a temp table #HasClaims.

The TempTable name with the Provider Id's(PRPR_ID) is
#TempFACETSNODu pes
The @identityID is an identity field counting back from 1494 to 1

I count back from the Max value of the identityid (1494) in the While
loop until I get through all the records. The idea is to check for the
existance of a claims and authorization record and put a 'Y' or 'N'
record in the temptable #HasClaims.

This is running in the Execute SQL Task object of the DTS Package.
The Package runs successfully but only inserts 200 rows into the new
temp table. There should be a row for each provider. Each time it
runs, the number of rows it returns is different. Sometimes it is 205,
then 185, then 210, before it completes the DTS package.

Has anyone run into While looping problems within an Execute SQL task
in a DTS package(SQL 2000)like this
--------------------------------------------------------------
SELECT @identityID = MAX(IDENTITYID) FROM #TempFACETSNODu pes
While @identityID >= 1

BEGIN
@PRPRID is the placeholder for the PRPR_ID (Provider)
SELECT @PRPRID = PRPR_ID FROM #TempFACETSNODu pes WHERE IDENTITYID =
@identityID

IF exists( SELECT CLCL_ID FROM dbo.CMC_CLCL_CL AIM CLCL WHERE
CLCL.PRPR_ID = @PRPRID)
BEGIN
INSERT INTO #HasClaims (PRPR_ID, HasClaims, IdentityID)
VALUES( @PRPRID, 'Y', @identityID)
END
ELSE INSERT INTO #HasClaims (PRPR_ID, HasClaims, IdentityID)
VALUES( @PRPRID, 'N', @identityID)

------------------------------------------------------------
SELECT @identityID = @identityID - 1
END

Jul 23 '05 #1
7 4979
Stu
Have you tried debugging it in Query Analyzer to ensure that the
problem is not with the code instead of simply the environment in which
you run it?

I am curious why you are looping, however, when you could accomplish
this process using a LEFT JOIN, like so:

INSERT INTO #HasClaims (PRPR_ID, HasClaims, IdentityID)
SELECT DISTINCT t.PRPID,
HasClaims = CASE WHEN CLCL.CLCL_ID IS NULL THEN 'N' ELSE 'Y' END,
t.IdentityID
FROM #TempFACETSNODu pes t LEFT JOIN dbo.CMC_CLCL_CL AIM CLCL ON
t.PRPID = CLCL.PRPID

HTH,
Stu

Jul 23 '05 #2
Stu,

First of all thanks for taking the time to reply!

The database that I am querying is a Sybase database. The Output is
dumped into a SQL 2000 database.
I am using the loop because of the size of the claims and
authorizations databases. When I use any JOIN the query times out.
This way of fetching a record at a time doesn't overpower the server.

When I use Query Tool(ADO) to run the exact same SQL query against the
Sybase database, The query returns all the records from the loop with
no problem. I would be done if not for the fact that this has to be
automated and delivered weekly. I don't want to manually construct
this every week.

I have tried the sql in an ODBC version of Query Tool just in case it
was the connection. Both query tool programs pulled the data without
problem. The DTS package is the only one that doesn't finish all the
updates. I have tried running the the Task all on the Main thread but
that didn't help.

Jul 23 '05 #3
Stu
So, as I understand it, the SQL statement you supplied is actually
running against the Sybase database. In other words, you have a
connection defined for the Sybase server, and you're using that
connection to build a temporary table on the Sybase Server, and then
you'll extract the information from that temp table to SQL Server. Is
that correct?

If so, it is very odd that it's not working as it should. Have you
considered building a linked server between your SQL Server and the
Sybase Server, and executing the code against the linked server to see
if that will correct it?

I'm shooting in the dark, to be honest. I've never heard of anything
like this.

Stu

Jul 23 '05 #4
Stu,

First of all thanks for taking the time to reply!

The database that I am querying is a Sybase database. The Output is
dumped into a SQL 2000 database.
I am using the loop because of the size of the claims and
authorizations databases. When I use any JOIN the query times out.
This way of fetching a record at a time doesn't overpower the server.

When I use Query Tool(ADO) to run the exact same SQL query against the
Sybase database, The query returns all the records from the loop with
no problem. I would be done if not for the fact that this has to be
automated and delivered weekly. I don't want to manually construct
this every week.

I have tried the sql in an ODBC version of Query Tool just in case it
was the connection. Both query tool programs pulled the data without
problem. The DTS package is the only one that doesn't finish all the
updates. I have tried running the the Task all on the Main thread but
that didn't help.

Jul 23 '05 #5
Stu
So, as I understand it, the SQL statement you supplied is actually
running against the Sybase database. In other words, you have a
connection defined for the Sybase server, and you're using that
connection to build a temporary table on the Sybase Server, and then
you'll extract the information from that temp table to SQL Server. Is
that correct?

If so, it is very odd that it's not working as it should. Have you
considered building a linked server between your SQL Server and the
Sybase Server, and executing the code against the linked server to see
if that will correct it?

I'm shooting in the dark, to be honest. I've never heard of anything
like this.

Stu

Jul 23 '05 #6
(ch*******@iwon .com) writes:
I am using the loop because of the size of the claims and
authorizations databases. When I use any JOIN the query times out.
This way of fetching a record at a time doesn't overpower the server.


Then you have something to fix. The temp table has 1494 rows that
is not much for a set-based query. For an interative loop, it's starting
to be a bit. You will take more power out of the server with the loop
that a good set-based query that inserts all rows in one go. What appears
to happen in your case, is that the loop times out as well. This is
possibly something you can control within DTS, but DTS is not my playground.

And, before I go on, if you really insist on the loop, make sure that
IdentityID is indexed.

Here are some possible variations of Stu's query:

INSERT INTO #HasClaims (PRPR_ID, HasClaims, IdentityID)
SELECT t.PRPID,
HasClaims = CASE WHEN EXISTS (SELECT *
FROM dbo.CMC_CLCL_CL AIM CLCL
WHERE t.PRPID = CLCL.PRPID)
THEN 'Y'
ELSE 'N'
END,
t.IdentityID
FROM #TempFACETSNODu pes

Or simply add a HasClaims to #TempFACETSNODu pes:

UPDATE #TempFACETSNODu pes
SET HasClaims = CASE WHEN EXISTS (SELECT *
FROM dbo.CMC_CLCL_CL AIM CLCL
WHERE t.PRPID = CLCL.PRPID)
THEN 'Y'
ELSE 'N'
END
FROM #TempFACETSNODu pes t

Or add this column with a default of 'N' and do:

UPDATE #TempFACETSNODu pes
SET HasClaims = 'Y'
FROM #TempFACETSNODu pes t
JOIN dbo.CMC_CLCL_CL AIM CLCL ON t.PRPID = CLCL.PRPID

If all these executes poorly, you need investigate why. I assume that
CMC_CLCL_CLAIM. PRDID is a primary key, so there is a good index to
use, but the Sybase optimizer may for some reason do a table scan.
But you should be able to convince it with an index hint.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #7
(ch*******@iwon .com) writes:
I am using the loop because of the size of the claims and
authorizations databases. When I use any JOIN the query times out.
This way of fetching a record at a time doesn't overpower the server.


Then you have something to fix. The temp table has 1494 rows that
is not much for a set-based query. For an interative loop, it's starting
to be a bit. You will take more power out of the server with the loop
that a good set-based query that inserts all rows in one go. What appears
to happen in your case, is that the loop times out as well. This is
possibly something you can control within DTS, but DTS is not my playground.

And, before I go on, if you really insist on the loop, make sure that
IdentityID is indexed.

Here are some possible variations of Stu's query:

INSERT INTO #HasClaims (PRPR_ID, HasClaims, IdentityID)
SELECT t.PRPID,
HasClaims = CASE WHEN EXISTS (SELECT *
FROM dbo.CMC_CLCL_CL AIM CLCL
WHERE t.PRPID = CLCL.PRPID)
THEN 'Y'
ELSE 'N'
END,
t.IdentityID
FROM #TempFACETSNODu pes

Or simply add a HasClaims to #TempFACETSNODu pes:

UPDATE #TempFACETSNODu pes
SET HasClaims = CASE WHEN EXISTS (SELECT *
FROM dbo.CMC_CLCL_CL AIM CLCL
WHERE t.PRPID = CLCL.PRPID)
THEN 'Y'
ELSE 'N'
END
FROM #TempFACETSNODu pes t

Or add this column with a default of 'N' and do:

UPDATE #TempFACETSNODu pes
SET HasClaims = 'Y'
FROM #TempFACETSNODu pes t
JOIN dbo.CMC_CLCL_CL AIM CLCL ON t.PRPID = CLCL.PRPID

If all these executes poorly, you need investigate why. I assume that
CMC_CLCL_CLAIM. PRDID is a primary key, so there is a good index to
use, but the Sybase optimizer may for some reason do a table scan.
But you should be able to convince it with an index hint.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8543
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An example of what I'm trying to do is below: update (tbl_ind_mananas LEFT JOIN (select count(*) as count, (dubicacion || zona || manzana) as cod_manzana from tbl_censo_poblacion_1993 group by dubicacion, zona, manzana) tbl1 on relacion = cod_manzana) as...
12
2327
by: Joe Stanton | last post by:
Hello Group I have a query that works in Oracle and SQL Server, but fails in Microsoft Access. The query is: SELECT data fromTABLE1 WHERE data>='A&' AND data<'A''' Here is my sample data:
6
7140
by: Andy | last post by:
Hello, I am having many problems with setting up a parameter query that searches by the criteria entered or returns all records if nothing is entered. I have designed an unbound form with 3 fields on it: Date (DateSpan1 and DateSpan2), Originator, and GroupName. I have added a button that triggers a query and uses those fields as its parameter criteria to populate a form. The user must be allowed to either enter all of the
3
11566
by: eagleofjade | last post by:
I am trying to help a friend who is learning VB.net in school. I have done VB programming for a number of years using VB 6. He needs to open a query in an Access database that has parameters so he can work with the returned records. In VB 6, I use DAO and do it this way: Dim db As Database Dim rs As Recordset Dim qd As QueryDef
5
7246
by: jonceramic | last post by:
Hi All, I started developing in Access, and people took notice and so we're starting to migrate into our corporate's bigger Oracle system. I'll still be using my developed Access front ends, but will be migrating my back ends to Oracle ODBC. 1. Does anyone have recommendations for books or web resources for general rules/guidelines/help on doing this? I haven't found a good
6
6051
by: OldBirdman | last post by:
I don't really know how to state this problem, as it doesn't make any sense to me. I have a simple "One-to-Many" query, and was updating the Many side. It quit working. I cannot make any changes to either side, to any field. To simplify the problem, I started from scratch and created 2 simple tables, 3 records in table=tOne, and 4 records in table=tMany. I used the DesignGrid to create queries for testing. tOne 'The table on the...
16
3526
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
4
1530
by: msalman | last post by:
Hey guys, I'm trying to update some columns in a table using another table's data but there seems to be some problem due to join among the two tables. Here is my query Update DMM_SalesReporting..sapis_test SET Claims_Qty = ISNULL(Claims_Qty, 0) + CONVERT(varchar(30), b.BaseUOMQuantity), Claims_Dollars = ISNULL(Claims_Dollars, 0) + b.BaseUOMAmount, Update_DateTime = getdate(), MM_Batch_Num = convert(varchar(30),...
1
20829
by: themightyrhino | last post by:
I'm writing a process to perform multiple updates on a main table from information stored in different component reports. As you can see from the below, I'm using a select query to base the update on. UPDATE DELTA_OD001_TMP TD SET (ORDER_DATE,VET_NO, VET_SCORE, VET_DECISION, PARTNER, ORANGE_ID) =(SELECT ORDER_DATE, VET_NO, VET_SCORE, VET_DECISION, PARTNER, ORANGE_ID FROM IMPORT_OD001_ORDERS IO WHERE TD.ORDER_NO = IO.ORDER_NO); ...
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10371
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3850
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.