帮忙看下 存储过程 不怎么会写

lijing3333 2011-06-08 06:33:08

create proc ['p_getUserGameCountTo10']
(
@award int,
@userId int,
@tid int,
@state int output
)
as
declare @gameCount int
declare @taskID int
declare @taskCount int
begin
set @taskCount = (SELECT count(1) FROM [LFDSDB].[dbo].[taskInfo] where [userId]=@userId)
if @taskCount = 0
begin
INSERT INTO [LFDSDB].[dbo].[taskInfo]([userId],[tid],[state],[addDate])VALUES(@userId,@tid,0,getdate())
end

if @taskCount=1
begin
set @gameCount=select (avg(WinCount)+avg(LostCount)+avg(DrawCount)+avg(FleeCount)) as resultCount from GameScoreInfo where UserID=@userId
if @gameCount>10
@state=2
else
@state=1
end
end








错误消息:
消息 156,级别 15,状态 1,过程 'p_getUserGameCountTo10',第 21 行
关键字 'select' 附近有语法错误。
消息 102,级别 15,状态 1,过程 'p_getUserGameCountTo10',第 23 行
'@state' 附近有语法错误。
...全文
69 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
--小F-- 2011-06-08
  • 打赏
  • 举报
回复
create proc ['p_getUserGameCountTo10']
(
@award int,
@userId int,
@tid int,
@state int output
)
as
declare @gameCount int
declare @taskID int
declare @taskCount int
begin
set @taskCount = (SELECT count(1) FROM [LFDSDB].[dbo].[taskInfo] where [userId]=@userId)
select @taskCount=count(1) from [LFDSDB].[dbo].[taskInfo] where [userId]=@userId
if @taskCount = 0
begin
INSERT INTO [LFDSDB].[dbo].[taskInfo]([userId],[tid],[state],[addDate])VALUES(@userId,@tid,0,getdate())
end

if @taskCount=1
begin
select @gameCount=(avg(WinCount)+avg(LostCount)+avg(DrawCount)+avg(FleeCount)) from GameScoreInfo where UserID=@userId
if @gameCount>10
set @state=2
else
set @state=1
end
end
打一壶酱油 2011-06-08
  • 打赏
  • 举报
回复
create proc ['p_getUserGameCountTo10']
(
@award int,
@userId int,
@tid int,
@state int output
)
as
declare @gameCount int
declare @taskID int
declare @taskCount int
begin
set @taskCount = (SELECT count(1) FROM [LFDSDB].[dbo].[taskInfo] where [userId]=@userId)
if @taskCount = 0
begin
INSERT INTO [LFDSDB].[dbo].[taskInfo]([userId],[tid],[state],[addDate])VALUES(@userId,@tid,0,getdate())
end

if @taskCount=1
begin
select @gameCount= (avg(WinCount)+avg(LostCount)+avg(DrawCount)+avg(FleeCount)) from GameScoreInfo where UserID=@userId
if @gameCount>10
set @state=2
else
set @state=1
end
end
叶子 2011-06-08
  • 打赏
  • 举报
回复

create proc ['p_getUserGameCountTo10']
(
@award int,
@userId int,
@tid int,
@state int output
)
as
declare @gameCount int
declare @taskID int
declare @taskCount int
begin
--set @taskCount = (SELECT count(1) FROM [LFDSDB].[dbo].[taskInfo] where [userId]=@userId)
select @taskCount=count(1) from [LFDSDB].[dbo].[taskInfo] where [userId]=@userId
if @taskCount = 0
begin
INSERT INTO [LFDSDB].[dbo].[taskInfo]([userId],[tid],[state],[addDate])VALUES(@userId,@tid,0,getdate())
end

if @taskCount=1
begin
select @gameCount=(avg(WinCount)+avg(LostCount)+avg(DrawCount)+avg(FleeCount)) from GameScoreInfo where UserID=@userId
if @gameCount>10
set @state=2
else
set @state=1
end
end

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧