SQL Server Database Error: 在关键字 'then' 附近有语法错误,请问是什么错误
useincome_clgocreatetriggerBudgetInsertonM_Budget_Dayafterinsertasbegindeclare@Budget...
use income_cl
go
create trigger BudgetInsert
on M_Budget_Day
after insert
as
begin
declare @BudgetYear int ,@ItemGroup varchar(10),@company varchar(10),@month int ,@count decimal(18,4)
set @month = (select month from inserted )
set @BudgetYear = (select budgetYear from inserted)
set @ItemGroup = (select ItemGroup from inserted)
set @company = (select company from inserted)
set @count = (select day1+day2+day3+day4+day5+day6+day7+day8+day9+day10+day11+day12+day13+day14+day15+day16+day17+day18+day19+day20+day21+day22+day23+day24+day25+day26+day27+day28+day29+day30+day31 from inserted);
if @month = 1 then
update M_Budget set Month1 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 2 then
update M_Budget set Month2 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 3 then
update M_Budget set Month3 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 4 then
update M_Budget set Month4 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 5 then
update M_Budget set Month5 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 6 then
update M_Budget set Month6 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 7 then
update M_Budget set Month7 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 8 then
update M_Budget set Month8 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 9 then
update M_Budget set Month9 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 10 then
update M_Budget set Month10 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 11 then
update M_Budget set Month11 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 12 then
update M_Budget set Month12 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
end if
end 展开
go
create trigger BudgetInsert
on M_Budget_Day
after insert
as
begin
declare @BudgetYear int ,@ItemGroup varchar(10),@company varchar(10),@month int ,@count decimal(18,4)
set @month = (select month from inserted )
set @BudgetYear = (select budgetYear from inserted)
set @ItemGroup = (select ItemGroup from inserted)
set @company = (select company from inserted)
set @count = (select day1+day2+day3+day4+day5+day6+day7+day8+day9+day10+day11+day12+day13+day14+day15+day16+day17+day18+day19+day20+day21+day22+day23+day24+day25+day26+day27+day28+day29+day30+day31 from inserted);
if @month = 1 then
update M_Budget set Month1 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 2 then
update M_Budget set Month2 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 3 then
update M_Budget set Month3 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 4 then
update M_Budget set Month4 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 5 then
update M_Budget set Month5 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 6 then
update M_Budget set Month6 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 7 then
update M_Budget set Month7 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 8 then
update M_Budget set Month8 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 9 then
update M_Budget set Month9 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 10 then
update M_Budget set Month10 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 11 then
update M_Budget set Month11 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
else if @month = 12 then
update M_Budget set Month12 = @count where BudgetYear = @BudgetYear and Company = @company and ItemGroup = @ItemGroup
end if
end 展开
1个回答
展开全部
删除then ,语法如下:
if (条件)
begin
语法
end
else
begin
语法2
end
if (条件)
begin
语法
end
else
begin
语法2
end
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |