我正在编写一个sql查询来从我们的一个链接oracle服务器中提取一些数据。
此查询的唯一问题是两个日期添加行(删除了查询运行)但我需要他们的数据。
我收到以下错误: OLE DB提供商" MSDAORA"对于链接服务器" MAGINUS"返回消息" ORA-00904:" DATEADD":无效标识符
有人可以为这些规定语法吗?
提前致谢
威尔
System.out.println(count(a));
答案 0 :(得分:0)
Dateadd
对SQL Server有效,但是您发送到Oracle数据库的查询需要对oracle有效。因此,您需要将dateadd移到openquery之外,并进入SQL Server位:
DECLARE @TSQL VARCHAR(8000)
,@CUSTOMER_ACCOUNT VARCHAR(20)
SELECT @TSQL1 = '
SELECT CustomerAccount
,ContactName
,MembershipNumber
,ProductDescription
,DATEADD(SECOND, MembershipStartDate, ''19700101'') AS MembershipStartDate
,DATEADD(SECOND, MemberhrshipEndDate, ''19700101'') AS MemberhrshipEndDate
,Price Paid
FROM OPENQUERY(MAGINUS,''
SELECT
CM.CUSTOMER_ACCOUNT AS "CustomerAccount"
,CM.CONTACT_NAME AS "ContactName"
,CM.MEMBERSHIP_NUMBER AS "MembershipNumber"
,P.LONG_DESCRIPTION_1 AS "ProductDescription"
,CM.MEMBERSHIP_START_DATE AS "MembershipStartDate"
,CM.MEMBERSHIP_EXPIRY_DATE AS "MemberhrshipEndDate"
,SH.ORDER_VALUE AS "Price Paid"
FROM MAGINUS.CUSTOMER_MEMBERSHIP CM
INNER JOIN MAGINUS.PRODUCT P
ON CM.PRODUCT_CODE = P.PRODUCT_CODE
INNER JOIN MAGINUS.SALES_HEADER SH
ON CM.CUSTOMER_ACCOUNT = SH.CUSTOMER_ACCOUNT
AND CM.SALES_DOCUMENT_NUM = SH.SALES_DOCUMENT_NUM
WHERE CM.CUSTOMER_ACCOUNT = ''''' + @CUSTOMER_ACCOUNT + ''''''')'
EXEC (@TSQL1)