use bbsDB
set nocount on
go
exec sp_helpconstraint bbsUsers
exec sp_helpindex bbsUsersuse master
go
exec xp_cmdshell 'mkdir D:\Project\text',no_output
exec xp_cmdshell 'dir D:\Project'
go
use bbsDB
go
if exists(select * from sysobjects where name='proc_fatie')
drop procedure proc_fatie
go
create procedure proc_fatie
@userName varchar(10),
@sentCount int output,
@replyCount int output,
@sectionName varchar(10)=null
as
declare @userID varchar(10),@sid int,@sqls varchar(200),@sqlr varchar(200)
select @userID=UID from bbsUsers where Uname=@userNameif (@sectionName is null)
begin
set @sqls=' TuID=@userID'
set @sqlr=' RuID=@userID'
end
else
begin
select @sid=SID from bbsSection where Sname=@sectionName
set @sqls=' TuID=@userID and TsID=@sid'
set @sqlr=' RuID=@userID and TsID=@sid'
endprint 'select * from bbsReply where'+@sqlr
exec('select * from bbsReply where'+@sqlr)
print 'select * from bbsReply where'+@sqlrif (exists(exec(@sqls)))
begin
print @userName+'发表的主贴如下:'
exec('select Ttime as 发帖时间,TclickCount as 点击率,Ttopic as 主题,Tcontents as 内容 from bbsTopic where'+@sqls)
exec('select @sentCount=count(*) from bbsTopic where'+@sqls)
end
else
print @userName+'在选择的版块没有发表过主贴!'
if exists(exec('select * from bbsReply where'+@sqlr))
begin
print @userName+'在选择的版块发表的回帖如下:'
exec('select Rtime as 回帖时间,RclickCount as 点击率,Rcontents as 回帖内容 from bbsReply where'+@sqlr)
exec('select @replyCount=count(*) from bbsReply where'+@sqlr)
end
else
print @userName+'在选择的版块没有发表过回帖!'
go
declare @Scount int,@Rcount int
exec proc_fatie '可卡因',@Scount output,@Rcount output
if(@Scount<>0 or @Rcount<>0)
begin
if(@Scount>@Rcount)
print '在选择的版块小弟发帖比回帖多,看来比较喜欢标新立异!'
else
print '在选择的版块小弟回帖比发帖多,看来比较关心民众疾苦!'
print '在选择的版块的总贴数:'+convert(varchar(5),@Scount+@Rcount)
end
go错误为:(创建过程里面的if和else和最后面的调用的exec)消息 156,级别 15,状态 1,过程 proc_fatie,第 26 行
关键字 'exec' 附近有语法错误。
消息 102,级别 15,状态 1,过程 proc_fatie,第 26 行
')' 附近有语法错误。
消息 156,级别 15,状态 1,过程 proc_fatie,第 32 行
关键字 'else' 附近有语法错误。
消息 156,级别 15,状态 1,过程 proc_fatie,第 34 行
关键字 'exec' 附近有语法错误。
消息 102,级别 15,状态 1,过程 proc_fatie,第 34 行
')' 附近有语法错误。
消息 156,级别 15,状态 1,过程 proc_fatie,第 40 行
关键字 'else' 附近有语法错误。
消息 2812,级别 16,状态 62,第 2 行
找不到存储过程 'proc_fatie'。