Sunday, July 06, 2014

Crystal Reports using SQL query

Steps:
  1. Select Blank Report  
  2. Database expert -> MyConnection 
  3. Give DB and Company credentials to establish the connection 
  4. Under server name expand the tree view
  5. Click on Add Command  
  6. Paste the query in the main command window 
  7. Add the parameters to the parameter list of the command,   (That's the skinnier window to the right of the main command window. Make sure you spell the names EXACTLY the way you spelled them in the Field Explorer.  
  8. Modify your SQL's WHERE clause to use the new parameters. Something like this...
    WHERE x.Date BETWEEN '{?BeginDate}' AND '{?EndDate}' 
  9. When you click "OK" you'll be prompted to enter values for your date parameters and CR will pass the SQL back to the server.
    Note: You can basically think of the parameters the same way you'd think of variables in SQL except you aren't declaring them in the SQL itself... you're adding them to the parameter list instead.Adding the parameter to the Select Expert WILL NOT push the filtering back to the server. The command will pull EVERY record that meets it's criteria and then CR will filter it locally
  10. Report in design mode
  11. Field Explorer > DatabaseFields > Command (containing columns from Query)