我尝试使用链接数据库代码中的另一个SP执行存储过程(SP),但没有错误,但它没有插入数据我的表。
以下是存储过程的代码
USE [MYDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[MYDB_SP]
@ReportDate smalldatetime ='19000101'
AS
IF(@ReportDate = '19000101')
SELECT @ReportDate = convert(varchar(10), GETDATE(), 112)
BEGIN
SELECT *
INTO #MYDBTABLETMP
FROM MYDBTABLE
INSERT INTO #MYDBTABLETMP
([DATAAREAID]
,[REPORTDATE]
,[ACCOUNTNUM]
,[NAME]
,[CUSTGROUP]
,[CURRENCYCODE]
,[TOTAL])
((select SPTABLE.[DATAAREAID]
,SPTABLE.[REPORTDATE]
,SPTABLE.[ACCOUNTNUM]
,SPTABLE.[NAME]
,SPTABLE.[CUSTGROUP]
,SPTABLE.[CURRENCYCODE]
,SPTABLE.[TOTAL]
FROM OPENROWSET('SQLOLEDB','LINKEDSERVER'; 'USERNAM' ; 'PASSWORD' ,
'SET FMTONLY OFF; SET NOCOUNT ON; exec LINKEDDB.LINKEDDB_SP 1,''20161201'' ') as SPTABLE))
delete MYDBTABLE where DATAAREAID = 'AAA'
INSERT INTO MYDBTABLE
SELECT * FROM #MYDBTABLETMP WHERE DATAAREAID = 'AAA'
DROP TABLE #ERPCUSTAGINGTMP
END
答案 0 :(得分:0)
尝试将 this 插入到程序中(=在BEGIN和END之间):
IF(@ReportDate = '19000101')
SELECT @ReportDate = convert(varchar(10), GETDATE(), 112)
现在你的脚本没有开始。并且只创建第一个语句集作为您的过程。
ALTER PROCEDURE [dbo].[MYDB_SP]
@ReportDate smalldatetime ='19000101'
AS
BEGIN
IF(@ReportDate = '19000101')
SELECT @ReportDate = convert(varchar(10), GETDATE(), 112)
...
END