日期:2014-05-19  浏览次数:20980 次

这两个存储过程有什么区别啊?
CREATE   procedure   titles_sum
@@TITLE   varchar(40)= '% ',
@@SUM   MONEY   output
as
select   'Tiltle   Name '=title         //与下面区别的地方
from   titles
WHERE   title   like   @@TITLE
SELECT   @@SUM=sum(price)                 //与下面区别的地方
from   titles
where   title   like   @@TITLE
GO


CREATE   procedure   titles_sum2
@@TITLE   varchar(40)= '% ',
@@SUM   MONEY   output
as
select   title   as   'Tiltle   Name '       //
from   titles
where   title   like   @@TITLE                  
select   sum(price)   as   Sum                 //
from   titles
where   title   like   @@TITLE
GO

同样用这个存储过程调用的
CREATE   PROCEDURE   test
as
BEGIN
declare   @totalcost   money
execute   titles_sum2   'The% ',@totalcost   output
if   @totalcost <20
begin
print ' '
print   'all   of   these   titles   can   be   purchased   for   less   than   $220. '
end
else
select   'The   tatal   cost   of   these   titles   is   $ '+rtrim(cast(@totalcost   as   varchar(20)))
end
GO
为什么产生的结果不一样??
select   sum(price)   as   Sum     和select   sum(price)   as   Sum   不一样吗??


------解决方案--------------------
第一种应该是对的
@@SUM=sum(price)
把值付给了参数

*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

最新版本:20070212

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
------解决方案--------------------
SELECT @@SUM=sum(price) --这里说明是把sum(price)的结果给了变量@@SUM


select sum(price) as Sum --这里只是把sum(price)做为Sum来显示,并没有给@@SUM



select 'Tiltle Name '=title

select title as 'Tiltle Name '

则是一样的.只是写法不同