一个出发器
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
但是当我运行程序时 出现将截断字符串或二进制数据 问题
前辈们解啊!

解决方案 »

  1.   

    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)))
    试试!
      

  2.   

    因为你的字符串转换成int值时出错了,或者超出了,int值的范围所以建议表即然是int操作,那就用int字段,
      

  3.   

    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表里的钱就不触发了?还没有错误?
      

  4.   

    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)
    问题解决了