通过来自 SQL 服务器的打开查询将参数传递给 Progress - 错误无效的日期字符串
Passing Parameter to Progress via Open Query from SQL Server - error Invalid date string
我正在使用 SQL Server 2014 并使用 OpenQuery 从 Progress 数据库中检索数据。
这是我的查询:
DECLARE @SOMONTH DATE;
SELECT @SOMONTH = DATEADD(DAY,1,EOMONTH(GETDATE (),-1));
SELECT t2.[Amount]
FROM OPENQUERY(MyServer,
' select top 50
t1."trn-val" as "Amount"
from myTable t1
WHERE t1."trn-dte" >= '''''' + @SOMONTH + ''''''
') AS t2
/*
Previous attempts -
WHERE t1."trn-dte" >= '''''' + CONVERT(VARCHAR(10),@SOMONTH,103) + ''''''
WHERE t1."trn-dte" >= ' + '''''' + CONVERT(VARCHAR(10),@SOMONTH,103) + '''''' + '
WHERE t1."trn-dte" >= '''''' + @SOMONTH + ''''''
WHERE t1."trn-dte" >= ' + '''''' + @SOMONTH + '''''' + '
WHERE t1."trn-dte" >= ''DATE(@SOMONTH)''
WHERE t1."trn-dte" >= TO_DATE(''@SOMONTH'')
WHERE t1."trn-dte" >= TO_DATE(''@SOMONTH'',''DD/MM/YYYY'')
WHERE t1."trn-dte" >= ''@SOMONTH''
*/
但是,我一直收到错误消息:
[DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Invalid date string (7497).
我错过了什么?
成功了:
DECLARE @TSQL varchar(8000)
declare @SOMONTH date
set @SOMONTH = DATEADD(DAY,1,EOMONTH(GETDATE (),-1));
DECLARE @Date nvarchar(10)=convert(nvarchar(10),@SOMONTH,23)
SELECT @TSQL = 'SELECT top 50 * FROM OPENQUERY([myserver], ''SELECT * FROM mytable
WHERE "trn-dte" >= ''''' + @Date + ''''''')'
EXEC (@TSQL)
Progress 知识库 000034986 说明了如何设置日期格式,如果您 google 于:
,这是第一次点击
site:progress.com sql92 date
因为我更喜欢 ISO 日期而不是任何其他猜测格式日期,所以这变成:
select top 50 t1."trn-val" as "Amount"
from myTable t1
where t1."trn-dte" >= { d 'yyyy-mm-dd' }
我不确定你的@sodate 是否已经是这种格式,或者你是否需要围绕你的添加日期进行额外的转换:
select @SOMONTH = convert( varchar, dateadd( day, 1, eomonth( getdate(), -1 ) ), 23 );
我正在使用 SQL Server 2014 并使用 OpenQuery 从 Progress 数据库中检索数据。
这是我的查询:
DECLARE @SOMONTH DATE;
SELECT @SOMONTH = DATEADD(DAY,1,EOMONTH(GETDATE (),-1));
SELECT t2.[Amount]
FROM OPENQUERY(MyServer,
' select top 50
t1."trn-val" as "Amount"
from myTable t1
WHERE t1."trn-dte" >= '''''' + @SOMONTH + ''''''
') AS t2
/*
Previous attempts -
WHERE t1."trn-dte" >= '''''' + CONVERT(VARCHAR(10),@SOMONTH,103) + ''''''
WHERE t1."trn-dte" >= ' + '''''' + CONVERT(VARCHAR(10),@SOMONTH,103) + '''''' + '
WHERE t1."trn-dte" >= '''''' + @SOMONTH + ''''''
WHERE t1."trn-dte" >= ' + '''''' + @SOMONTH + '''''' + '
WHERE t1."trn-dte" >= ''DATE(@SOMONTH)''
WHERE t1."trn-dte" >= TO_DATE(''@SOMONTH'')
WHERE t1."trn-dte" >= TO_DATE(''@SOMONTH'',''DD/MM/YYYY'')
WHERE t1."trn-dte" >= ''@SOMONTH''
*/
但是,我一直收到错误消息:
[DataDirect][ODBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Invalid date string (7497).
我错过了什么?
成功了:
DECLARE @TSQL varchar(8000)
declare @SOMONTH date
set @SOMONTH = DATEADD(DAY,1,EOMONTH(GETDATE (),-1));
DECLARE @Date nvarchar(10)=convert(nvarchar(10),@SOMONTH,23)
SELECT @TSQL = 'SELECT top 50 * FROM OPENQUERY([myserver], ''SELECT * FROM mytable
WHERE "trn-dte" >= ''''' + @Date + ''''''')'
EXEC (@TSQL)
Progress 知识库 000034986 说明了如何设置日期格式,如果您 google 于:
,这是第一次点击site:progress.com sql92 date
因为我更喜欢 ISO 日期而不是任何其他猜测格式日期,所以这变成:
select top 50 t1."trn-val" as "Amount"
from myTable t1
where t1."trn-dte" >= { d 'yyyy-mm-dd' }
我不确定你的@sodate 是否已经是这种格式,或者你是否需要围绕你的添加日期进行额外的转换:
select @SOMONTH = convert( varchar, dateadd( day, 1, eomonth( getdate(), -1 ) ), 23 );