一个触发器问题请大家帮忙修改!很着急
CREATE TRIGGER [trig_omsYunDanJian_Insert]
ON [dbo].[omsYunDanJian]
AFTER INSERT
AS
--声明变量
Declare @m_zhongliang decimal(7,2)
declare @m_tiji decimal(15,6)
BEGIN
SET NOCOUNT ON;
@m_zhongliang = select 'ZL '=SUM(ZhongLiang)
from omsYunDanJian
where omsYunDanJian.YunDanID=inserted.YunDanID
@m_tiji= select 'TJ '=SUM(TiJi)
from omsYunDanJian
where omsYunDanJian.YunDanID=inserted.YunDanID
if(@m_zhongliang > 0 || @m_tiji > 0)
UPDATE omsYunDan
SET
ZhongLiang = @m_zhongliang ,
TiJi=@m_tiji=
from inserted
WHERE omsYunDan.YunDanID = inserted.YunDanID
SET NOCOUNT OFF
END
请大家帮我修改一下这个触发器!
------解决方案--------------------差不多这样吧
CREATE TRIGGER [trig_omsYunDanJian_Insert]
ON [dbo].[omsYunDanJian]
AFTER INSERT
AS
--声明变量
Declare @m_zhongliang decimal(7,2)
declare @m_tiji decimal(15,6)
BEGIN
SET NOCOUNT ON
select @m_zhongliang = SUM(ZhongLiang) as 'ZL ', @m_tiji = SUM(TiJi) as 'TJ '
from omsYunDanJian
where omsYunDanJian.YunDanID=inserted.YunDanID
if(@m_zhongliang > 0 || @m_tiji > 0)
UPDATE omsYunDan
SET ZhongLiang = @m_zhongliang , TiJi = @m_tiji
from omsYunDan inner join inserted
on omsYunDan.YunDanID = inserted.YunDanID
SET NOCOUNT OFF
END
------解决方案--------------------select @m_zhongliang = SUM(ZhongLiang) as 'ZL ', @m_tiji = SUM(TiJi) as 'TJ '
=============================================================================
select 用法有错;
SELECT @var1 = 'Generic Name '
SELECT @var1 AS 'Company Name '
不能 SELECT @m_zhongliang = SUM(ZhongLiang) AS 'ZL '
------解决方案--------------------select @m_zhongliang = SUM(ZhongLiang), @m_tiji = SUM(TiJi)
from omsYunDanJian inner join inserted
on omsYunDanJian.YunDanID=inserted.YunDanID