你好
我写了一个存储过程,让返回给定名字的人的信息.
如何写一个传出参数将这个记录返回来呢?
------解决方案--------------------
@参数 类型 output
as
set @参数='值'
------解决方案--------------------
--完整示例:
create PROCEDURE judge_sunday @count int output
as
begin
declare @startDate datetime,@endDate datetime,@numDays int--,@count int
set @startDate = DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)
set @endDate = DATEADD(day,-1,DATEADD(mm,1,@startDate))
set @numDays = datediff(day, @startDate, @endDate) + 1;
With NumDays as
(
select top(@numDays) row_number() over(order by (select 0)) as n from sys.objects
)
select @count=count(*) from NumDays
where DATEPART(WEEKDAY,convert(varchar(10), dateadd(day, NumDays.n - 1, @startDate), 120))=1
return @count
end
--执行
declare @count int;
exec @count=judge_sunday @count;
select @count
------解决方案--------------------
你执行完存储过程,让结果直接select 一行你想要的结果,不是一样吗?
为何非要out 参数返回一条记录?
------解决方案--------------------
一个int类型怎么可能保存一条记录?直接select,不用返回了。
------解决方案--------------------
不过用string返回倒也可以,将记录拼接赋值给返回参数。
------解决方案--------------------
create proc [存储过程名]
(@name varchar(20))
as
begin
select *
from [表名]
where 姓名=@name
end
------解决方案--------------------