Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2008, 06:29 PM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default SProc generates different results same data

I hope this won't be another head smacker, but What could cause a stored procedure to generate different result sets for the same data when the procedure is run from the same machine in the same software (SQL Server Managment Studio Express) just moments apart. There is one parameter which is a datetime. I'm using the same parameter over and over. Sometimes it generates the correct result and sometimes it doesn't. When I run the same stored procedure on my development machine it always works. But on the company test server it is intermittent.

The only thing I have found is that it seems like you get the correct result if you haven't run the procedure in a while. But that's pretty vague.

I think someone has ... SET AFU ON;

What you don't know can hurt you!
__________________
What you don\'t know can hurt you!
 
Old June 12th, 2008, 07:28 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Heh... the SET AFU ON may be in the form of unwanted parallelism. Development machines usually only have one or two processors which tend to limit parallelism to none... the test server may have more processors so parallelism can occur. Check the actual execution plan on both machines... see what the difference is...

--Jeff Moden
 
Old June 13th, 2008, 06:46 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Jeff,

Can you explain why parallelism would result in different results?

-Peter
compiledthoughts.com
 
Old June 13th, 2008, 01:22 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

If there's anything that even comes close to a procedural task or something that's order dependent but ORDER BY hasn't been used, there's no guarantee what order parallelism would do something in. I'd have to see the code to know for sure...

--Jeff Moden
 
Old June 16th, 2008, 01:34 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sometimes even parameter sniffing throws a different execution plan.


 
Old June 16th, 2008, 05:52 PM
Authorized User
 
Join Date: Nov 2006
Posts: 93
Thanks: 0
Thanked 1 Time in 1 Post
Default

This is a fairly complex stored procedure. Though I have seen some that were a lot more complex. Essentially the procedure declares a temporary table (@tmpDevices) then populates it with the devices available on the specified date through a couple of INSERT INTO statements.

The next piece uses a cursor to select any updates and apply them to the available devices. Finally a SELECT statement is called on the temporary table to return the records. Here's the cursor portion:

Code:
    DECLARE
        curTmp CURSOR FOR
        SELECT ri.ANALYZER_ID, ri.ITEM_TYPE, idt.ITEM_DATE_ID, idt.CHECKED 
        FROM (appToledoCEM.REPORT_ITEMS ri INNER JOIN appToledoCEM.STATUS_REPORT sr 
        ON ri.STATUS_REP_ID = sr.STATUS_REP_ID) INNER JOIN appToledoCEM.ITEM_DATES idt 
        ON ri.REPORT_ITEM_ID = idt.REPORT_ITEM_ID 
        WHERE sr.REPORT_DATE = @repdate
        ORDER BY ri.ANALYZER_ID, ri.ITEM_TYPE, idt.ITEM_DATE_ID, idt.CHECKED;

            OPEN curTmp;

            WHILE @@FETCH_STATUS = 0
            BEGIN
                FETCH NEXT FROM curTmp INTO @analid, @ittype, @itemid, @checked;

                UPDATE @tmpDevices SET CHECKED = @checked, ITEM_DATE_ID = @analid 
                WHERE ANALYZER_ID = @analid AND ITEM_TYPE = @ittype;
            END;

            CLOSE curTmp;

            SELECT * FROM @tmpDevices ORDER BY ITEM_TYPE, ORDER_NUM;
With the test data I'm using there is only one device that needs to have CHECK set to 1 but it will only do it the first time I run the procedure after not running it for a long time (hours). Even if I edit the stored procedure and re-run it, it doesn't see the Checked item.

I can run the same SELECT statement I used to declare the cursor immediately before I open the cursor. This causes me to get 2 result sets back, the first set shows the one device I need checked. But the second set doesn't.

I added "SELECT @analid, @ittype, @itemid, @checked;" right after the FETCH statement. This give me 2 result sets (where I expected 3), the first is the one record from the Cursor SELECT statement and the second is the final result set. But I didn't get a set for the SELECT following the FETCH.

All in all I'm pretty confused and looking for another way to do this.

Any ideas?

Thanks






What you don't know can hurt you!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I change how VS2008 generates certain items? chobo2 C# 2008 aka C# 3.0 1 October 8th, 2008 04:16 PM
generates aspx pages dynamically and compile also shadab_17 ASP.NET 1.0 and 1.1 Professional 0 February 28th, 2007 02:35 AM
xslt_create occasionally generates Fatal Error csbdeady XSLT 1 March 16th, 2006 01:35 AM
data shaping... slooooow results page pshudgins Classic ASP Databases 0 June 23rd, 2005 02:01 PM
DLL generates Database read-only error Howard Classic ASP Databases 0 July 19th, 2003 08:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.