Knowledgebase
[QODBC-Desktop] ProfitAndLossByClass Report Fails in OPENQUERY Due to an Invalid Column in the SHOW Clause
Posted by William - QODBC Support on 19 October 2026 06:15 AM

[QODBC-Desktop] ProfitAndLossByClass Report Fails in OPENQUERY Due to an Invalid Column in the SHOW Clause

Problem Description:

You are unable to execute the ProfitAndLossByClass report through SQL Server OPENQUERY when using dynamically constructed SQL with date parameters. The query fails because the AmountTitle column is specified in the report's show clause, although it is not available for this report.

Affected products: QODBC Desktop, SQL Server. Expected outcome: You can successfully execute the ProfitAndLossByClass report through OPENQUERY using a variable date range, summarized by Class and using the Cash reporting basis.

Symptoms:

  • The ProfitAndLossByClass report fails to execute through OPENQUERY.
  • The query includes AmountTitle in the show clause, but this column is not available for the report.
  • Changing the dynamic date parameter construction does not resolve the issue.
  • The original query uses spreport, while the successfully tested query uses sp_report.
  • The outer SQL statement includes SELECT TOP 20, which is unnecessary for the tested query.

Cause:

The query includes AmountTitle in the show clause, but this column does not exist in the available columns for the ProfitAndLossByClass report. The query must use supported report columns, such as Text, Label, and Amount.

The date parameters were confirmed to be working correctly. The successfully tested query uses sp_report, removes AmountTitle, and omits the outer TOP 20 clause.

Resolution:

Verify the Available Report Columns

  1. Review the available columns for the ProfitAndLossByClass report using the official documentation: Available Columns for ProfitAndLossByClass Report.
  2. Remove AmountTitle from the show clause because it is not an available column for this report.
  3. Use supported columns such as Text, Label, and Amount.

Execute the Corrected SQL Query

Use the following query to execute the report through OPENQUERY with a variable date range:


DECLARE @TestFrom char(10) = '2026-09-01';
DECLARE @TestTo char(10) = '2026-09-30';

DECLARE @TestInner nvarchar(1000) =
'sp_report ProfitAndLossByClass show Text, Label, Amount '
+ 'parameters DateFrom = {d''' + @TestFrom + '''}, '
+ 'DateTo = {d''' + @TestTo + '''}, '
+ 'SummarizeColumnsBy = ''Class'', '
+ 'ReportBasis = ''Cash''';

DECLARE @TestSql nvarchar(max) =
N'SELECT * FROM OPENQUERY(QRemote, '''
+ REPLACE(@TestInner, '''', '''''')
+ N''');';

EXEC sys.sp_executesql @TestSql;

Verify the Results

  1. Execute the corrected query in SQL Server.
  2. Confirm that the report executes successfully for the specified date range.
  3. Verify that the report is summarized by Class and uses the Cash reporting basis.

Additional Notes:

  • The date parameters were confirmed to be working correctly. Changing their formatting was not required to resolve the issue.
  • Verify report column availability before using the show clause. Refer to the report-specific column documentation when troubleshooting similar errors.
  • The successfully tested query uses sp_report rather than spreport. Use the syntax shown in the corrected query.
  • The example uses September 1–30, 2026. Replace these dates with the required reporting period.

Example Scenarios:

Scenario 1 - Running a Profit and Loss by Class report for a variable date range:

A user attempts to execute the ProfitAndLossByClass report through SQL Server OPENQUERY using dynamically constructed date parameters, the Class summary option, and the Cash reporting basis. The query includes AmountTitle in the show clause, but this column is not available for the report. Removing the invalid column and using the tested query with supported columns allows the report to execute successfully.

How are dates formatted in SQL queries when using the QuickBooks generated timestamps? Troubleshooting - How to use parameters in OPENQUERY

Keywords:

ProfitAndLossByClass OPENQUERY SQL Server AmountTitle sp_report Dynamic Date Parameters SummarizeColumnsBy ReportBasis Cash Basis Report Columns
(0 vote(s))
Helpful
Not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
CAPTCHA Verification 
 
Please complete the captcha below (we use this to prevent automated submissions).