我正在尝试使用我们的postgres数据库来获取一份报告,以便在Crystal中运行。
我的SQL看起来像
SELECT
slcnote.note_date,
slcnote.account,
customer.name,
slcnote.reference,
slcnote.operator,
salesman.name,
slcnote.system_date,
slcnote.note_type,
slcnote.note_note,
CAST(salesman.code as integer)
FROM
slcnote
Left JOIN customer ON slcnote.account=customer.account
left JOIN salesman ON slcnote.operator=salesman.code
ORDER BY "slcnote"."note_date"
但是,似乎并没有将推销员代码转换为整数。我在Crystal Reports中遇到以下错误消息:
--------------------------- Crystal Reports --------------------------- Failed to retrieve data from the database. Details: 42883: ERROR: operator does not exist: integer = character varying; Error while executing the query [Database Vendor Code: 7 ] --------------------------- OK ---------------------------
感谢帮助
克里斯
答案 0 :(得分:1)
您的问题是,在salesman.code
子句中将SELECT
强制转换为整数,但在ON
子句中未强制转换。因此,查询试图通过将integer
与VARCHAR
进行比较来联接表,从而生成错误消息。
要解决您眼前的问题,您需要在ON
子句中执行强制转换:
SELECT * FROM slcnote LEFT JOIN salesman ON CAST(salesman.code AS INT) = slcnote."operator"
但是,如注释中所述,此查询的性能将很糟糕。如果无法更改表,是否可以创建执行转换的实例化视图?这可能会有所帮助。您还应该引用这些性能问题,看看能够 更改表的个人是否会这样做。