Knowledgebase
[QODBC-Desktop] How to Run sp_report Queries from SQL Server Management Studio Using OPENQUERY
Posted by William - QODBC Support on 19 October 2026 09:10 AM

[QODBC-Desktop] How to Run sp_report Queries from SQL Server Management Studio Using OPENQUERY

Problem Description:

Users need to pull QuickBooks reports (such as Profit and Loss, Balance Sheet, etc.) from SQL Server Management Studio (SSMS) using QODBC's linked server connection. Standard table queries work via OPENQUERY, but sp_report stored procedure calls require a specific syntax pattern.

Affected products: QODBC Desktop, QODBC Online
Expected outcome: Run sp_report queries from SSMS using OPENQUERY with proper escaping and parameter syntax to retrieve report data into SQL Server tables or views.

Symptoms:

  • Standard table SELECT queries work via OPENQUERY, but sp_report calls return errors or empty results in SSMS.
  • Users are unsure how to format report parameters (date ranges, summarization options) within the OPENQUERY string context.
  • Error messages about quote escaping when trying to pass multi-level SQL strings (OPENQUERY outer quotes + sp_report inner quotes).

Cause:

sp_report queries run through OPENQUERY require double-nested string contexts. The OPENQUERY function takes a linked server name and a SQL string. When that inner SQL string calls an sp_report stored procedure with its own parameter syntax (which uses single quotes), those inner quotes must be escaped by doubling them (e.g., '') so they pass through the OPENQUERY layer correctly.

Environment:

QuickBooks Desktop Edition: Enterprise, Pro, Premier

RequirementDetail
QODBC Version All versions (Desktop or Online)
Data Source MS SQL Server Management Studio (SSMS), SQL Server Agent, any OLE DB consumer
Linked Server A QODBC-linked server must be pre-configured in SSMS (e.g., "QRemote" for QODBC Online)

Solution:

Step 1: Confirm Your Linked Server Name

In SSMS, check that your QODBC linked server is registered. The linked server name appears in the OPENQUERY call as the first argument - it must match exactly what is configured in SSMS.

Step 2: Basic sp_report Query Syntax

The basic pattern for running any report via OPENQUERY:

SELECT * FROM OPENQUERY(QRemote, 'sp_report ReportName')

Replace QRemote with your actual linked server name, and ReportName with the desired report (e.g., ProfitAndLossStandard, BalanceSheetSummary, TransactionList).

Step 3: sp_report with Parameters

To include parameters and column selections, use the full syntax with escaped quotes:

SELECT * FROM OPENQUERY(QRemote, 'sp_report ProfitAndLossStandard show Amount_Title, Text, Label, Amount parameters DateMacro = ''ThisMonthToDate'', SummarizeColumnsBy = ''Month''')

Key formatting rules:

  1. Double all inner single quotes. The OPENQUERY layer strips one level of escaping; any quote that should reach the sp_report engine must be doubled ('') inside the OPENQUERY string.
  2. The outer quote style is always single-quote. Use 'sp_report ...' as the OPENQUERY second argument - do not use double quotes for the outer layer.
  3. Column names after show must match the report's field names exactly. Reference the QODBC data layouts documentation to verify available columns for each report.

Step 4: Common Report Examples

Profit and Loss standard (all months):

SELECT * FROM OPENQUERY(QRemote, 'sp_report ProfitAndLossStandard')

Profit and Loss by Class (year-to-date):

SELECT * FROM OPENQUERY(QRemote, 'sp_report ProfitAndLossByClass show Amount_Title, Text, Label, Amount parameters DateMacro = ''ThisYearToDate'', SummarizeColumnsBy = ''Class''')

Balance Sheet Summary:

SELECT * FROM OPENQUERY(QRemote, 'sp_report BalanceSheetSummary')

Trial Balance (custom date range):

SELECT * FROM OPENQUERY(QRemote, 'sp_report TrialBalance show AccountName, AccountNumber, AccountType, Debit_Title, Credit_Title, Label, Debit, Credit parameters DateFrom={d''2026-06-29''}, DateTo={d''2026-06-30''}')

Step 5: Available Reports Reference

A complete list of available sp_report reports and their parameters is documented at QODBC Desktop Reports Documentation.


Example Scenarios:

Scenario 1 - Monthly financial reporting in SSRS/Power BI:

A business needed to pull monthly Profit and Loss data from QuickBooks Desktop into SQL Server for SSRS report generation. The team configured a QODBC linked server named "QRemote" and created an OPENQUERY-based view that pulls the report with DateMacro = 'ThisMonthToDate'. A SQL Server Agent job scheduled weekly refreshes of the underlying table, which SSRS reports consumed directly.

Scenario 2 - Audit trail extraction via sp_report:

A customer needed to export all transactions for a specific date range into SQL Server for custom audit reporting. They used sp_report TransactionList with OPENQUERY, passing DateFrom and DateTo parameters with properly escaped quotes. The result was bulk-inserted into a SQL Server audit table for downstream processing.

Additional Notes:

  • OPENQUERY is server-side. The query string executes on the QODBC/QRemote side - not in SQL Server. SQL Server simply receives the result set.
  • DateMacro parameter values include: 'Today', 'Yesterday', 'ThisDayToDate', 'ThisMonth', 'ThisMonthToDate', 'LastMonth', 'ThisYearToDate'. For custom ranges, use DateFrom and DateTo.
  • Performance note: sp_report queries retrieve the full report result set from QuickBooks. For large company files with extensive transaction history, consider limiting the date range to reduce load time.
  • Quote escaping is case-sensitive for report/field names (e.g., ProfitAndLossStandard), but not for SQL keywords. Double-check spelling against the QODBC data layouts documentation.

How to Setup QODBC Linked Server in SSMS QODBC Data Layouts Reference sp_report Parameter Reference Guide

Keywords:

OPENQUERY SSMS sp_report SQL Server Profit and Loss Linked Server Report Query QRemote Excel Quote Escaping QuickBooks Desktop QuickBooks Online
(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).