As the title says, I've built a Crystal Report to pull data from a SQL server. The SQL query that Crystal Reports generates pulls the data as expected when copied into SSMS but pulls no records when the report is run from Crystal Reports.
My record selection:
({PRECEIPTD.CREDAT_0} >= {?startDate} AND {PRECEIPTD.CREDAT_0} <= {?endDate})
AND ISNULL({PINVOICED.NUM_0})
AND IF ISNULL({?bpr}) OR {?bpr} = "" THEN {PORDERQ.BPSNUM_0} = {PORDERQ.BPSNUM_0} ELSE {PORDERQ.BPSNUM_0} = {?bpr}
I've also tried writing the selection like this, which pulls all of the same records:
({PRECEIPTD.CREDAT_0} >= {?startDate} AND {PRECEIPTD.CREDAT_0} <= {?endDate})
AND ISNULL({PINVOICED.NUM_0})
AND IF ISNULL({?bpr}) OR {?bpr} = "" THEN {PORDERQ.BPSNUM_0} LIKE "*" ELSE {PORDERQ.BPSNUM_0} = {?bpr}
I'm using Crystal Reports 2013 SP11, accessing the database through a ODBC connection.
EDIT: The SQL query Crystal generates:
SELECT
PRECEIPTD.CREDAT_0
, PORDERQ.BPSNUM_0
, PORDERQ.POHNUM_0
, PORDERQ.ITMREF_0
, PORDERQ.QTYPUU_0
, PORDERP.NETPRI_0
, PRECEIPTD.PTHNUM_0
, PINVOICED.NUM_0
FROM ((x3v6.PROD.PORDERQ PORDERQ
INNER JOIN x3v6.PROD.PORDERP PORDERP ON
(PORDERQ.POHNUM_0=PORDERP.POHNUM_0)
AND (PORDERQ.POPLIN_0=PORDERP.POPLIN_0))
LEFT OUTER JOIN x3v6.PROD.PRECEIPTD PRECEIPTD ON
((PORDERQ.POPLIN_0=PRECEIPTD.POPLIN_0)
AND (PORDERQ.POQSEQ_0=PRECEIPTD.POQSEQ_0))
AND (PORDERQ.POHNUM_0=PRECEIPTD.POHNUM_0))
LEFT OUTER JOIN x3v6.PROD.PINVOICED PINVOICED ON
(PRECEIPTD.PTHNUM_0=PINVOICED.PTHNUM_0)
AND (PRECEIPTD.PTDLIN_0=PINVOICED.PTDLIN_0)
WHERE
(PRECEIPTD.CREDAT_0>={ts '2018-01-01 00:00:00'} AND PRECEIPTD.CREDAT_0<{ts '2019-01-01 00:00:00'})
AND PINVOICED.NUM_0 IS NULL
AND PORDERQ.BPSNUM_0=PORDERQ.BPSNUM_0
ORDER BY
PORDERQ.BPSNUM_0
, PRECEIPTD.CREDAT_0