sql运行错误,如何修改....

tanyuqiong 2006-07-14 01:23:12
declare @var_now datetime
set @var_now=getdate()
declare @ee int
set @ee=(select datediff(dd,paydays,nextpaydays) from client as a left join clientpay as b on a.pkid=b.clientid and (b.paytoflag=1) where a.producttype=1)
declare @ff int
set @ff=(select datediff(dd,paydays,@var_now) from client as a left join clientpay as b on a.pkid=b.clientid and (b.paytoflag=1) where a.producttype=1 )
begin tran shiwu
if @ee> @ff
begin
select a.pkid,a.clientname,a.contractprice,a.qiantime,a.producttype,b.payid,b.paydays,b.nextpaydays,gou from client as a left join clientpay as b on a.pkid=b.clientid and (b.paytoflag=1) where a.producttype=1
end
else
if @ee< @ff
begin
select a.pkid,a.clientname,a.contractprice,a.qiantime,a.producttype,b.payid,b.paydays,b.nextpaydays,cha from client as a left join clientpay as b on a.pkid=b.clientid and (b.paytoflag=1) where a.producttype=1
end
commit tran shiwu
...全文
123 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellowork 2006-07-14
  • 打赏
  • 举报
回复
set @ee=(select datediff(dd,paydays,nextpaydays) from ....)
set @ff=(select datediff(dd,paydays,@var_now) from ....)
以上二个语句使用的子查询返回的结果多余一行.SQLSERVER要求子查询结果用于运算赋值时,必须保证子查询结果只有一行.
请楼主修改子查询的过滤条件,使查询结果唯一.
或者在子查询中
1.使用top 1限定只返回一行.
2.使用max(),min(),sum()等聚合函数.
tanyuqiong 2006-07-14
  • 打赏
  • 举报
回复
Server: Msg 512, Level 16, State 1, Line 4
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Server: Msg 512, Level 16, State 1, Line 6
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
persley 2006-07-14
  • 打赏
  • 举报
回复
什么错误啊?

34,590

社区成员

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

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