我要做的就是将一个变量设置为受事务影响的行数并将其发送到表中。我不知道为什么我遇到了麻烦,但这是我的代码
Begin
Declare @errDate datetime
Declare @RowCount nvarchar(10)
Declare @Message nvarchar(max)
Declare @startproc datetime
Declare @endproc datetime
Declare @duration int
set @startproc = getdate()
Declare @myDate Datetime
Set @myDate = CAST(CONVERT(varchar,getdate()-1, 112) +' ' +'00:00 AM'AS DATETIME)
DELETE FROM [Cal_CommOps].[dbo].[Progression_PreCall_CaliforniaECH]
Where segStart_date = @myDate
INSERT INTO [Cal_CommOps].[dbo].[Progression_PreCall_CaliforniaECH]
([callid]
,[segstart_date]
,[dialed_num]
,[origlogin]
,[duration])
SELECT *
FROM (
Select callid,
CAST ([SEGSTART_D] as datetime) as segstart_date,
RIGHT(dialed_num, 10) as dialed_num,
origlogin,
duration
FROM [CMS_ECH] ECH
Inner join [Cal_CommOps].[dbo].[CommOps_Emp] EMP on EMP.extension = ECH.origlogin
AND Dept in ('Pre-Call')
Where [SEGSTART_D] = @myDate and dialed_num <> ''
UNION
Select callid,
CAST ([SEGSTART_D] as datetime) as segstart_date,
RIGHT(calling_pty, 10) as dialed_num,
anslogin,
duration
FROM [CMS_ECH] ECH
Inner join [Cal_CommOps].[dbo].[CommOps_Emp] EMP on EMP.extension = ECH.anslogin
AND Dept in ('Pre-Call')
Where [SEGSTART_D] = @myDate and calling_pty <> ''
) as myCalls
Set @RowCount = @@rowcount
Set @endproc = getdate()
Set @duration = DATEDIFF(minute, @startproc, @endproc)
Set @errDate = getdate()
Exec usp_myDashboardInsert 'PreCall_ECH', @@Rowcount, @errDate, @duration
End
即使我尝试
Exec usp_myDashboardInsert 'PreCall_ECH', @Rowcount, @errDate, @duration
我仍然得到1。
为什么会这样,我该如何解决?
如果我更改代码并在Select @@ROWCOUNT
之前添加,Set @RowCount = @@rowcount
那么它可以选择它,但我仍然希望它在一个变量中。
回答:我猜这是@@ROWCOUNT 我使用@@Rowcount 的情况,它需要@@ROWCOUNT。