SQL使用带默认参数的存储过程?(菜鸟急问)

[复制链接]
查看11 | 回复1 | 2011-3-5 00:28:30 | 显示全部楼层 |阅读模式
(1)要求创建存储过程 proc_find3,查询某个用户在某个版块的发帖情况(主帖+回帖),并返回发帖数和主贴数。如果调用者没有指定具体的版块,则默认为所有版块。
(2)编写存储过程proc_findReply,查询某个主帖的所有回帖,并返回回帖的数量。
提示:
(1)添加输入参数:版块名称 @SecName varchar(10),默认值为空 null。
(2)调整参数的顺序,推荐将具有默认值的参数放置在最后。
(3)在存储过程中判断版块名称是否为空:is null。
(4)录用不同的调用方式进行测试。
(数据库bbsDB请加QQ1014682675附上加我的原因,谢谢啊!!):
在以下SQL代码下进行修改:
if exists(select * from sysobjects where name='proc_find2')
drop procedure proc_find2
go
create procedure proc_find2
@userName varchar(10),
@sumTopic int output,
@sumReply int output
as
set nocount on
declare @userID varchar(10)
select @userID=UID from bbsUsers where Uname=@userName
if exists(select * from bbsTopic where Tuid=@userID)
begin
select @sumTopic=count(*) from bbsTopic where Tuid=@userID
print @userName+'发表的主贴如下:'
select 发帖时间=convert(varchar(10),Ttime,111),点击率=TclickCount,主题=Ttopic,内容=Tcontents from bbsTopic where Tuid=@userID
end
else
begin
set @sumTopic=0
print @userName+'没有发表过主贴'
end
if exists(select * from bbsReply where Ruid=@userID)
begin
select @sumReply=count(*) from bbsReply where Ruid=@userID
print @userName+'发表的回帖如下:'
select 回帖时间=convert(varchar(10),Rtime,111),点击率=RclickCount,回帖内容=Rcontents from bbsReply where Ruid=@userid
end
else
begin
set @sumReply=0
print @userName+'没有发表过回帖。'
end
go
declare @sum1 int ,@sum2 int
exec proc_find2 '可卡因',@sum1 output,@sum2 output
if @sum1>@sum2
print '小弟发帖比回帖多,看来比较喜欢标新立异!'
else
print '小弟回帖比发帖多,看来比较关系民众疾苦!'
print '总贴数:'+convert(varchar(5),@sum1+@sum2)
go

回复

使用道具 举报

千问 | 2011-3-5 00:28:30 | 显示全部楼层
md.commandtext="p"
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行