declare @Maxamount int,
@month varchar,
@Duration int,
@iReturn int
set @month = (select DATEPART(MM,start_date) from TC_Project_Referal where id_tc_projuser = @id_tc_projuser)
set @Duration = (select fixeddDuration from TC_Project_Referal where id_tc_projuser = @id_tc_projuser)
select @Maxamount = @month+@Duration-1
子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。我在数据库中有超过1条记录。数据将根据ID显示。我们也可以为单个id提供多个记录。然后如何
答案 0 :(得分:0)
使用INTO。
select DATEPART(MM,start_date) **into** @month from TC_Project_Referal where id_tc_projuser = @id_tc_projuser;
select fixeddDuration **into** @Duration from TC_Project_Referal where id_tc_projuser = @id_tc_projuser;
select @Maxamount := @month+@Duration-1;
答案 1 :(得分:0)
如果您的内部查询碰巧返回多行,则会出现以下错误
子查询返回的值超过1。这是不允许的 子查询跟随=,!=,<,< =,>,> =或当子查询用作 表达。
确保查询使用TOP子句
返回单个记录declare @Maxamount int,
@month varchar,
@Duration int,
@iReturn int
set @month = (select TOP 1 DATEPART(MM,start_date) from TC_Project_Referal where id_tc_projuser = @id_tc_projuser order by start_date)
set @Duration = (select TOP 1 fixeddDuration from TC_Project_Referal where id_tc_projuser = @id_tc_projuser order by id_tc_projuser )
select @Maxamount = @month+@Duration-1