帮忙进来看一下触发器

zey95125923 2008-12-27 12:09:08
一个出发器
create trigger updateorderb2
on dbo.orderbl
for update
as
update dbo.orderxx set ifmoney=1 where orderID=(select top 1 orderrand from inserted)
update users set usermoney='convert((CONVERT(select usermoney from users where username=(select top 1 username from inserted))as decimal)
-CONVERT((select totleprice from orderbl where orderrand=(select top 1 orderrand from inserted)) as decimal) as nvarchar(50))' where username=(select top 1 username from inserted)


当更新orderbl中的inmoney=1的时候 同时更新 orderxx里所有外键=刚更新的主键值
然后同时把用户表中钱数减去相应的totleprice
由于totleprice和usermoney都为nvarchar(50)所以我把他转换成decimal
但是当我运行程序时 出现将截断字符串或二进制数据 问题
前辈们解啊!
...全文
61 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zey95125923 2008-12-27
  • 打赏
  • 举报
回复
create trigger updateorderb2
on dbo.orderbl
for update
as
update dbo.orderxx set ifmoney=1 where orderID=(select top 1 orderrand from inserted)
update users set usermoney=CAST((CAST((select usermoney from users where username=(select top 1 username from inserted))as int(4))
-CAST((select totleprice from orderbl where orderrand=(select top 1 orderrand from inserted)) as int(4))) as nvarchar(50)) where username=(select top 1 username from inserted)


前一条都触发了
怎么更新USERS表里的钱就不触发了?还没有错误?
Fibona 2008-12-27
  • 打赏
  • 举报
回复
因为你的字符串转换成int值时出错了,或者超出了,int值的范围

所以建议表即然是int操作,那就用int字段,

vlysses 2008-12-27
  • 打赏
  • 举报
回复
convert(nvarchar(CONVERT(decimal(select usermoney from users where username=(select top 1 username from inserted),2))
-CONVERT(decimal(select totleprice from orderbl where orderrand=(select top 1 orderrand from inserted),2)))
试试!
zey95125923 2008-12-27
  • 打赏
  • 举报
回复
顶一下
zey95125923 2008-12-27
  • 打赏
  • 举报
回复
create trigger updateorderb2
on dbo.orderbl
for update
as
update dbo.orderxx set ifmoney=1 where orderID=(select top 1 orderrand from inserted)
update users set usermoney=CAST((CAST((select usermoney from users where username=(select top 1 username from inserted))as decimal(9))
-CAST((select totleprice from orderbl where orderrand=(select top 1 orderrand from inserted)) as decimal(9))) as nvarchar(50)) where username=(select top 1 username from inserted)


问题解决了

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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