September 30, 2009 at 4:03 am
Hi,
I have this stored procedure:
CREATE PROCEDURE dbo.GetObsliquidacao
@num_liq varchar(50),
@ObsBloco varchar(50)=null out,
@Obsarea varchar(50)=null out,
@Obs varchar(50)=null out
WITH ENCRYPTION
AS
declare @a int
exec @a = dbo.IsDliInObsliquidacao @num_liq
if (@a<>0)
begin
SELECT @ObsBloco= ObsBloco, @Obsarea = Obsarea, @Obs = Obs FROM OBSLIQUIDACAO WHERE codobsliq = @a
end
select @ObsBloco as ObsBloco, @Obsarea as Obsarea, @Obs as Obs
as you can see , this stored procedure, call another stored proc inside.
The code, of the called stored procedure is:
CREATE PROCEDURE dbo.IsDliInObsliquidacao @num_liq nvarchar(50)
WITH ENCRYPTION
AS
return (SELECT codobsliq FROM OBSLIQUIDACAO where NUMLIQ=@num_liq)
When the table don't have any records to return, in SQL Server 2000 the result of the stored proc is Null,Null,Null and that is correct.
In SQL Server 2005, when i execute the same stored procedure the result returned is Null,Null.NULL but it raises the message:
The 'IsDliInObsliquidacao' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead.
(1 row(s) affected)
This causes problems in my vb app, so i had to change the code of the called procedure to:
alter PROCEDURE dbo.IsDliInObsliquidacao @num_liq nvarchar(50)
WITH ENCRYPTION
AS
if (SELECT count(codobsliq) FROM OBSLIQUIDACAO where NUMLIQ=@num_liq) =0
begin
return 0
end
else
return (SELECT codobsliq FROM OBSLIQUIDACAO where NUMLIQ=@num_liq)
Can someone explain me, why the procedure works correctly in SQL Server 2000 and not in SQL server 2005?
Thanks
September 30, 2009 at 8:53 am
Is any of your stored procedure making use of NOCOUNT ON?
MJ
September 30, 2009 at 9:09 am
No
October 1, 2009 at 8:50 am
You relied on using a feature that you are not supposed to use. RETURN is not for output parameters or values, which is what you used it for. Thus when microsoft changed the functionality your code broke.
Also, it was suboptimal to use that design in the first place. You should have directly made the table hit in the main sproc. 🙂 Failing that you should use an output parameter in the subordinate sproc.
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
October 1, 2009 at 3:32 pm
Kevin,
I'll admit to being a bit lazy here... do you have a link about that change? Thanks.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 1, 2009 at 3:55 pm
Jeff Moden (10/1/2009)
Kevin,I'll admit to being a bit lazy here... do you have a link about that change? Thanks.
No I do not - I just assumed there was a change since the user is getting two different outcomes on different versions.
2005 BOL: ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/1d9c8247-fd89-4544-be9c-01c95b745db0.htm. I note here that 2000 BOL states the same thing about NULL value getting converted to 0 and a warning message being raised. Perhaps the message severity is different and/or for some other reason the calling mechanism used by OP handles/ignores said warning??
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply