Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: view and stored proc...proc runs for every row Post Reply Post New Topic
Author Message
bobogs
Newbie
Newbie


Joined: 06 Aug 2008
Location: United States
Online Status: Offline
Posts: 1
Quote bobogs Replybullet Topic: view and stored proc...proc runs for every row
    Posted: 06 Aug 2008 at 7:20pm
Crystal 9, SQL 2000, OLEDB (ADO).

I have a report that uses a view and a stored procedure (with parameters) as its two data tables.  The view and proc are inner joined in the Database Expert->Links.

The proc's parameters, provided upon each report run, give it a set of rows that matches very closely to the view's rows, which are filtered down using a Selection Formula.

What's weird is that SQL Profiler shows the following steps during the execution of the report...

1. The view is queried using the Selection Formula filter...this takes a few seconds (in Profiler).  As an example, this step might return 500 rows from the view.

2. According to Profiler, it appears that the stored procedure is being executed multiple times, over and over again.  If I watch the statusbar of the Crystal Reports window, the Profiler messages seem to align with the "Reading Records...x of y" status messages.  This leads me to believe that the procedure is being executed once for each of the view's rows.  This is incredibly inefficient for what this report is suppoed to do.

I would expect that the procedure would run once using the supplied params, then its results are presented to the report as a table, to be joined with the filtered view's results.  Anyone know why the procedure is executing this other, inefficient way?

Thanks!
Gary
IP IP Logged
cwillsh
Newbie
Newbie
Avatar

Joined: 20 Dec 2007
Location: United States
Online Status: Offline
Posts: 4
Quote cwillsh Replybullet Posted: 07 Aug 2008 at 8:38am

This is how I filter my report to include the data requested by the user via a parameter:  ' Where gstcd_zip = ''32225'''.  I use a view to return only the primary key of the table along with any fields that I allow the user to add for criteria such as name, site, city, etc.  Then I link the view in the stored proc so it only returns the records requested, along with any other fields I want to include in the report.  NOW, I don't know if it is any more efficient.  But it work!

 
CREATE PROCEDURE procRptGuestList
 @pchrWhere varchar(500) = NULL
AS
DECLARE @vSql nvarchar(1000)
--create the temporary table
CREATE TABLE #xtmpSelect (gstcn varchar(50))
--update with the records to be selected
Set @vSql = 'INSERT #xtmpSelect(gstcn) SELECT DISTINCT gstcn FROM viewRptSelGuestList '
Set @vSql = @vSql + @pchrWhere
EXEC sp_executesql @vSql
--return the recordset for the report
SELECT tblGuest.gstnm_last, tblGuest.gstnm_first, tblSite.stenm
FROM tblGuest
INNER JOIN tblSite
ON tblGuest.gstky_ste = tblSite.stecn
INNER JOIN #xtmpSelect
ON tblGuest.gstcn = #xtmpSelect.gstcn
ORDER BY tblGuest.gstnm_last, tblGuest.gstnm_first
GO
 
CREATE VIEW dbo.viewRptSelGuestList
AS
SELECT gstcn, gstky_ste, gstnm_last, gstdt, gstcd_zip
FROM tblGuest
Thanks for your help,
cwillsh
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.