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
GOCREATE 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 不一样吗??
@@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
GOCREATE 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(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
select sum(price) as Sum --这里只是把sum(price)做为Sum来显示,并没有给@@SUM
而
select 'Tiltle Name'=title
和
select title as 'Tiltle Name' 则是一样的.只是写法不同