473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
#TempFACETSNODupes
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 #TempFACETSNODupes
While @identityID >= 1

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

IF exists( SELECT CLCL_ID FROM dbo.CMC_CLCL_CLAIM 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 4957
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 #TempFACETSNODupes t LEFT JOIN dbo.CMC_CLCL_CLAIM 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_CLAIM CLCL
WHERE t.PRPID = CLCL.PRPID)
THEN 'Y'
ELSE 'N'
END,
t.IdentityID
FROM #TempFACETSNODupes

Or simply add a HasClaims to #TempFACETSNODupes:

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

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

UPDATE #TempFACETSNODupes
SET HasClaims = 'Y'
FROM #TempFACETSNODupes t
JOIN dbo.CMC_CLCL_CLAIM 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****@sommarskog.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_CLAIM CLCL
WHERE t.PRPID = CLCL.PRPID)
THEN 'Y'
ELSE 'N'
END,
t.IdentityID
FROM #TempFACETSNODupes

Or simply add a HasClaims to #TempFACETSNODupes:

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

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

UPDATE #TempFACETSNODupes
SET HasClaims = 'Y'
FROM #TempFACETSNODupes t
JOIN dbo.CMC_CLCL_CLAIM 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****@sommarskog.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
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...
12
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
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...
3
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...
5
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,...
6
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...
16
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...
4
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.