我正在尝试将变量传递给 OPENROWSET 中的 SELECT 语句,但我不断收到错误消息
DECLARE @dDateTIME DATE
SET @dDateTIME = (SELECT SalesDate FROM dbo.SalesDate)
INSERT INTO dbo.tblSales
SELECT * FROM OPENROWSET('MSDASQL', 'dsn=mydsn;uid=myid;pwd=mypwd;',
'SELECT
ID,
TranDate,
ProductID,
CostValue,
SalesValue,
QtySold,
FROM tblSales WHERE TranDate='' + @dDateTIME + ''')
DECLARE @dDateTIME DATE
SET @dDateTIME = (SELECT SalesDate FROM dbo.SalesDate)
DECLARE @SQL NVARCHAR(1024) =
'SELECT
ID,
TranDate,
ProductID,
CostValue,
SalesValue,
QtySold,
FROM tblSales WHERE TranDate=''' + CAST(@dDateTIME AS VARCHAR(64)) + ''''
DECLARE @RunSQL NVARCHAR(max)
SET @RunSQL=
'SELECT * FROM OPENROWSET (''MSDASQL'', ''dsn=mydsn;uid=myid;pwd=mypwd;'',''EXEC @SQL'')'`
我使用什么语法来应用@SQL
?
我得到的错误是:
错误是:OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface]Error in predicate: TranDate = '(SELECT @ dDateTIME)' "