Data Connectivity
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Data Connectivity
Message Icon Topic: Difference in a procedure using curor? Post Reply Post New Topic
Author Message
rezourxe
Newbie
Newbie
Avatar

Joined: 25 Mar 2008
Location: Dominican Republic
Online Status: Offline
Posts: 1
Quote rezourxe Replybullet Topic: Difference in a procedure using curor?
    Posted: 25 Mar 2008 at 11:40am
hi,

people, is there any difference when my stored procedure is selecting from a cursor? when I create the dataset, it doesn't show fields for the procedure.
so, the same happens on the report wizard.

I really don't know if this problem is caused for circumstances on Crystal Reports or it's the Stored Procedure.

heres the procedure:



Create PROCEDURE dbo.[PaymentInformation_T_CalculateBonus]
(
@FromDate DATETIME,
@ToDate DATETIME
)

AS

DECLARE @VENTAS INT
DECLARE @AGENT VARCHAR(50)
DECLARE @Bonos INT
DECLARE @Pay DECIMAL(10,2)
DECLARE @ProductID INT
DECLARE @ProductoNomre VARCHAR(200)
DECLARE @QTY INT
DECLARE @LE INT
DECLARE @LG INT

--Declare the cursor
DECLARE @Cursor CURSOR
SET @Cursor = Cursor
FOR
SELECT T.[proID], P.[Product], COUNT(1) AS QTY, p.[SalesAgent]
FROM [transactions_V] T
INNER JOIN [PaymentInformation_V] p ON t.[payID] = p.[payID]
INNER JOIN [ReferenciasValores_V] r ON t.[proID] = r.[ValorID]
WHERE T.[Result] LIKE 'Completed%'
AND p.[SalesAgentID] IS NOT NULL
AND p.[SalesAgent] IS NOT NULL
AND t.[Date] BETWEEN @FromDate AND @ToDate
AND t.transactiontype in ('Enrollment')
GROUP BY p.[SalesAgent], T.[proID], P.[Product]
ORDER BY p.SalesAgent

/*
Temp Table to Hold The Calculated Rows
*/

CREATE TABLE #BonosInformation
(
AgentID INT,
Agente VARCHAR(50),
ProductoID INT,
ProductoNombre VARCHAR(200),
Ventas INT,
CantReqPorBono INT,
Precio INT,
TotalBonos INT,
FromDate DATETIME,
ToDate DATETIME
)

OPEN @Cursor
FETCH @Cursor INTO @ProductID, @ProductoNomre, @VENTAS, @AGENT

WHILE @@FETCH_STATUS = 0
BEGIN
SET @LE = 100000
SELECT
    @LG = MAX(PackMinimum),
    @Pay = MAX(PackPrice)
FROM [BonusPackages_V]
WHERE packminimum < @LE
AND ProID = @ProductID
GROUP BY proid

WHILE @LE > 1
Begin
    SET @Bonos = @Pay * CONVERT(INT,@VENTAS/@LG)
   
     INSERT INTO [#BonosInformation] (
        [Agente],
        ProductoID,
        [ProductoNombre],
        Ventas,
        [CantReqPorBono],
        [Precio],
        [TotalBonos],
        [FromDate],
        [ToDate]
    ) VALUES (
    @AGENT,
    @ProductID,
    @ProductoNomre,
    @Ventas,
    @LG,
    @Pay,
    @Bonos,
    @FromDate,
    @ToDate
             )
             
    SET @LE = @LG
    SET @Ventas = @Ventas-(CONVERT(INT,@VENTAS/@LG)*@LG);
    SELECT
        @LG = MAX(PackMinimum),
        @Pay = MAX(PackPrice)
    FROM [BonusPackages_V]
    WHERE packminimum < @LE
    AND ProID = @ProductID
    GROUP BY proid
END
FETCH @Cursor INTO @ProductID, @ProductoNomre, @VENTAS, @AGENT
END


SELECT * FROM #BonosInformation WHERE [TotalBonos] > 0
DROP TABLE #BonosInformation
CLOSE @Cursor



is a little long... but i wanted to make sure I was showing everything...

thanks in advance...
Enter a signature that you would like shown at the bottom of your Forum Posts (max 200 characters)
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 25 Mar 2008 at 9:51pm
I'm pretty sure that the problem is due to the output when creating the temporary tables. CR takes thinks that these status messages are a record set and doesn't know what to do with it. This is a common problem b/c most people don't realize that it is happening behind the scenes. What you need to do is add this to the top of the stored procedure
SET NOCOUNT ON

This turns the status messages off so that CR only sees the final data from the SELECT statement.

I cover many tips and techniques for improving how your reports connect to databases in Chapter 10 and 11 of my Encyclopedia book. You can find out more about my books at Amazon.com or reading the Crystal Reports eBooks online.

Edited by BrianBischof - 25 Mar 2008 at 9:53pm
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
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.027 seconds.