{"id":210,"date":"2007-12-30T21:37:20","date_gmt":"2007-12-31T04:37:20","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/crystal-reports-xi\/1015-connecting-to-stored-procedures\/"},"modified":"2007-12-30T21:37:20","modified_gmt":"2007-12-31T04:37:20","slug":"1015-connecting-to-stored-procedures","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/1015-connecting-to-stored-procedures\/","title":{"rendered":"10.15 Connecting to Stored Procedures"},"content":{"rendered":"<h1>Connecting to Stored Procedures<\/h1>\n<p>As mentioned earlier in the chapter, stored procedures can be used as a data source just like a table. Crystal Reports can open a stored procedure, retrieve the data and print it. The benefit of using stored procedures is that they let you use the SQL language to process complex logic that isn&#8217;t possible just by linking two tables together.<\/p>\n<blockquote><p>If your database has stored procedures but you don&#8217;t see them listed in the Database Expert dialog box, it&#8217;s probably because the option to view them has been disabled. To enable them, select the menu options File > Options and click on the Database tab. In the middle section, you&#8217;ll see a Stored Procedures checkbox. Check it to tell Crystal Reports to list them.<\/p><\/blockquote>\n<p>The one thing that can make retrieving data from a stored procedure unique is when it has input parameters. When a stored procedure uses input parameters, it has to be given a value for each parameter before it can run. Crystal Reports does this for you by automatically creating a new report parameter for every parameter in the stored procedure. It also gives the new report parameter the same name as the stored procedure parameter. So there is a one-to-one mapping of parameters between the stored procedure and the report and they have identical names and data types. When the report runs, the user is prompted to enter a value for each report parameter and Crystal Reports passes these parameter values to the stored procedure.<\/p>\n<p>Let&#8217;s look at a sample stored procedure. The following code is a stored procedure from the Northwind database.&#x2;<\/p>\n<p>         <code_Single>CREATE PROCEDURE CustOrderHist<\/code_Single><br \/>\n         <code_Single>@CustomerID nchar(5)<\/code_Single><br \/>\n         <code_Single>AS<\/code_Single><br \/>\n         <code_Single>SELECT ProductName, Total=SUM(Quantity)<\/code_Single><br \/>\n         <code_Single>FROM Products P, [Order Details] OD, Orders O, Customers C<\/code_Single><br \/>\n         <code_Single>WHERE C.CustomerID = @CustomerID<\/code_Single><br \/>\n         <code_Single>AND C.CustomerID = O.CustomerID<\/code_Single><\/p>\n<p>In this stored procedure, there is one input parameter called @CustomerID and it is a 5 character string. When this stored procedure is selected as the data source for a report, Crystal Reports automatically creates a report parameter called @CustomerID as a String data type. The report prompts the user to enter a Customer ID when it runs.  The report passes this value to the stored procedure and the stored procedure only returns records with a matching ID.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Connecting to Stored Procedures As mentioned earlier in the chapter, stored procedures can be used as a data source just like a table. Crystal Reports can open a stored procedure, retrieve the data and print it. The benefit of using stored procedures is that they let you use the SQL language to process complex logic [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,1],"tags":[],"class_list":["post-210","post","type-post","status-publish","format-standard","hentry","category-chapter-10-connecting-to-databases","category-crystal-reports-xi","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=210"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/210\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}