向变量赋值的select不能与数据检索一起使用,是什么错误?

vc_human 2003-12-16 12:15:12
select inout_date,summary ,merchant_provider,card_patch ,sign_expired,sum( in_amount ),sum( out_amount), @store=@store+sum( in_amount )-sum( out_amount)
from #t
请问我想实现这样的功能这样好像不行啊
日期 摘要 名称 入库批次 充值有效期 入库数量 出库 库存
2003-08-01入库 移动 001 10 10
2003-08-02出库 711 3 7
2003-08-02出库 百佳 7 0
2003-08-17入库 移动 003 5 5
2003-08-22出库 711 4 1

合计 — — — 15 14 1
...全文
103 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wolfyang 2003-12-16
  • 打赏
  • 举报
回复
没有group by 怎么行啊
vc_human 2003-12-16
  • 打赏
  • 举报
回复
看来也只能这样了
武哥博文 2003-12-16
  • 打赏
  • 举报
回复
采用临时表和游标进行操作
vc_human 2003-12-16
  • 打赏
  • 举报
回复
我知道错误原因了select检索的数据不能和变量赋值一起用,那请问我想实现这样的功能应该怎么去做呢?
ghosthjt 2003-12-16
  • 打赏
  • 举报
回复
如果要用sum,count(),avg等到的聚合函数,一定要用group by.
select inout_date,summary ,merchant_provider,card_patch ,sign_expired,sum( in_amount ),sum( out_amount), @store=@store+sum( in_amount )-sum( out_amount)
from #t
group by inout_date,summary,merchant_provider,card_patch ,sign_expired
vc_human 2003-12-16
  • 打赏
  • 举报
回复
不过好像不是这个错误啊。。。。。
select convert(varchar(10),inout_date,120),summary ,merchant_provider,card_patch ,sign_expired,sum( in_amount ) amount_in,sum( out_amount) amount_out , @store=@store+sum( in_amount ) -sum( out_amount) stroe
from #t
group by convert(varchar(10),inout_date,120),summary ,merchant_provider,card_patch ,sign_expired
还是一样的错误
vc_human 2003-12-16
  • 打赏
  • 举报
回复
哈哈`~~~~。

34,590

社区成员

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

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