SAP Knowledge Base Article - Public

1531012 - How to create a Command Object in Crystal Reports?

Symptom

  • How to report off your own SQL Query?
  • Where can we enter a manually written SQL Query in Crystal Reports?
  • How to create a Command Object to enter your own SQL Query in Crystal Reports, or Crystal Reports for Enterprise?
          
             
  • Note: Images and data in this SAP Knowledge Base Article are from SAP internal systems, sample data, or demo systems. Any resemblance to real data is purely coincidental.

Environment

  • SAP Crystal Reports 2013
  • SAP Crystal Reports 2016
  • SAP Crystal Reports 2020
            
  • SAP Crystal Reports for Enterprise 4.1
  • SAP Crystal Reports for Enterprise 4.2
  • SAP Crystal Reports for Enterprise 4.3

Resolution

  • Command Objects allows the report developer to write his own SQL Query which will be represented in Crystal Reports as a table. 
     
    Important Notes:  
       
    Command Object is a powerful feature that enables a report developer to enter a SQL Query manually to retrieve data, but with power, comes responsibilities, therefore when using a Command Object to enter a SQL Query, it is the report developer's responsibility to ensure the SQL Query syntax is correct. If you need assistance in writing the SQL Query, contact your database administrator, or consult your database documentation.
         
    Also, Crystal Reports supports SQL Query Language in a Command Table to retreive data from a data source like: SELECT, FROM, WHERE, GROUP BY, ORDER BY, UNION. Crystal Reports does not support SQL Query Language for data manipulation like: CREATE TABLE, ALTER TABLE, INSERT, INTO, UPDATE, DELETE, DROP TABLE, ALTER SESSION, TEMP Table, Variable Declaration,... This is because Crystal Reports is a reporting tool, and not a data manipulation tool.
      
    For reference, see the Crystal Reports User Guide section on: How To Create a Command Object
            
        
  • To create a report off a Command Object:
      
       
    • In Crystal Reports
         
      1. In Crystal Reports, create a report off your data source.
          
      2. In the "Database Expert", under the connection to your data source, double-click on "Add Command"
          
        Command Objects - 02.png
             
           
      3. In the "Add Command To Report" window, enter the SQL Query manually, for example:
          
             Select Product_Name, Country, Cost
             From Product
             Where Cost <= 15        
            
      4. Click "OK" to create the Command Object.
         
            
               
    • In Crystal Reports for Enterprise 
       
      1. In Crystal Reports for Enterprise, create a new report, and connect to your data source.
            
      2. Still in the "Choose a Data Source Connection" window, under "Available Tables", click on the button: "Add Command"
         
        Command Objects - 01.png  
          
          
      3. Enter a name for the Command Object, or use the default name proposed, and click "OK"
           
      4. In the "Add Command Table" window, enter the SQL Query manually, for example:  
          
             Select Product_Name, Country, Cost
             From Product
             Where Cost <= 15        
                
      5. Click "OK" to create the Command Object.          

Keywords

Command Object Table, SQl Server 2005, SQL Server 2008, Crystal Report 2008 , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To

Product

SAP Crystal Reports 2013 ; SAP Crystal Reports 2016 ; SAP Crystal Reports 2020