[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

Calling stored proc and running procedure sql give different resul

Herbman

3/23/2007 3:32:00 PM

Hi,

I have a stored procedure that accepts a parameter used to output the results.
when I execute this stored procedure, I get different result than if I were
to
execute the stored procedures code in sql query analyzer:


In SQL Query Analyzer I run the following:

DECLARE @StatusId int
SET @StatusId = 1 -- not issued

SELECT Count(Workordernumber) AS WorkOrderCount,
rg.[Name] AS Region,
ar.[Name] AS Area,
SUM(a.TotalProjectedHours) AS [Total Projected Hours],
SUM(a.TotalHourlyCharges) AS [Total Hourly Charges],
SUM(a.TotalNonHourlyCharges) AS [Total Non-Hourly Charges],
SUM(a.TotalNucReimbursementCharges) AS [Extra Receipt Reimbursements],
SUM(a.TotalNucHourlyCharges) AS [Extra Hourly Charges],
SUM(a.TotalNucActualHours) AS [Extra Actual Hours],
SUM(a.TotalProjectedHours + a.TotalNucHourlyCharges) AS [Approved Hours],
SUM(a.GrandTotal) AS [Grand Total]

FROM WorkOrders a, Regions rg, Areas ar

WHERE
a.ContractorID = 'bd71cab0-a9bf-4d20-ae5c-7009c7c49c06'
AND a.RegionId = rg.RegionId
AND a.AreaId = ar.AreaId
AND a.StatusId != @StatusId

GROUP BY rg.[Name], ar.[Name]
GO

If I call
exec procCntrGetWorkOrderSummary 'bd71cab0-a9bf-4d20-ae5c-7009c7c49c06'

I get a different result.



My procedure is the following:

CREATE PROCEDURE [dbo].[procCntrGetWorkOrderSummary]
@ContractorID uniqueidentifier

AS

DECLARE @StatusId smallint

SET @StatusId = 1 -- not issued

SELECT Count(Workordernumber) AS WorkOrderCount,
rg.[Name] AS Region, ar.[Name] AS Area,
SUM(a.TotalProjectedHours) AS [Total Projected Hours],
SUM(a.TotalHourlyCharges) AS [Total Hourly Charges],
SUM(a.TotalNonHourlyCharges) AS [Total Non-Hourly Charges],
SUM(a.TotalNucReimbursementCharges) AS [Extra Receipt Reimbursements],
SUM(a.TotalNucHourlyCharges) AS [Extra Hourly Charges],
SUM(a.TotalNucActualHours) AS [Extra Actual Hours],
SUM(a.TotalProjectedHours + a.TotalNucHourlyCharges) AS [Approved Hours],
SUM(a.GrandTotal) AS [Grand Total]

FROM WorkOrders a, Regions rg, Areas ar

WHERE
a.ContractorID = @ContractorID
AND a.RegionId = rg.RegionId
AND a.AreaId = ar.AreaId
AND a.StatusId != @StatusId

GROUP BY rg.[Name], ar.[Name]
GO


Am I missing something?

1 Answer

Hugo Kornelis

3/25/2007 11:50:00 AM

0

On Fri, 23 Mar 2007 08:32:08 -0700, Herbman wrote:

>Hi,
>
>I have a stored procedure that accepts a parameter used to output the results.
>when I execute this stored procedure, I get different result than if I were
>to
>execute the stored procedures code in sql query analyzer:
(snip)

Hi Herbman,

The most probable explanation is a difference in the settings used. Most
likely candidate would be SET ANSI_NULLS, which determines if a NULL is
considered neither equal nor unequal to anything, including another NULL
(the ANSI behavior), or whether NULL is considered equal to another NULL
(mainly for compatibility with older code that relies on pre-ANSI
behavior).

I recommend you yo recreate the stored proc with SET ANSI_NULLS OFF,
then run the query and the stored pproc (bth with ANSI_NULLS OFF). If
you still get different results, we'll have to dig further.

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hug...