DECLARE
@sql
NVARCHAR(
MAX),
@FName
NVARCHAR(
50)
DECLARE
@Nn
DECIMAL(
18,
0),
@On
DECIMAL(
18,
0),
@Nc
DECIMAL(
18,
0),
@Oc
DECIMAL(
18,
0)
SET
@sql
= N
'
SELECT @Nn = [
'
+
CONVERT(
NVARCHAR(
MAX),
@I)
+
'
n],@Nc = [
'
+
CONVERT(
NVARCHAR(
MAX),
@I)
+
'
c] FROM #inserted
'
EXECUTE sp_executesql
@sql,
N
'
@Nn DECIMAL(18,0) OUTPUT,@Nc DECIMAL(18,0) OUTPUT
',
@Nn OUTPUT,
@Nc OUTPUT;
SET
@sql
= N
'
SELECT @On = [
'
+
CONVERT(
NVARCHAR(
MAX),
@I)
+
'
n],@Oc = [
'
+
CONVERT(
NVARCHAR(
MAX),
@I)
+
'
c] FROM #deleted
'
EXECUTE sp_executesql
@sql,
N
'
@On DECIMAL(18,0) OUTPUT,@Oc DECIMAL(18,0) OUTPUT
',
@On OUTPUT,
@Oc OUTPUT;
IF (
ISNULL(
@Nn,
0)
<>
ISNULL(
@On,
0))
--
EXECUTE [dbo].[usp_Audit_Insert] ...
IF (
ISNULL(
@Nc,
0)
<>
ISNULL(
@Oc,
0))
--
EXECUTE [dbo].[usp_Audit_Insert] ...