# Please Help Correct the Code

**URL:** <https://forum.kirupa.com/t/please-help-correct-the-code/285768>\
**Category:** programming\
**Created:** [April 6, 2009, 7:48am UTC](https://forum.kirupa.com/t/please-help-correct-the-code/285768 "2009-04-06T07:48:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vova1981](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@Vova1981](https://forum.kirupa.com/u/Vova1981)\
**Post date:** [April 6, 2009, 7:48am UTC](https://forum.kirupa.com/t/please-help-correct-the-code/285768/1 "2009-04-06T07:48:00Z")

</div>

Hi, See The Code Below, It is giving me an error and i wanted to be able to see how the SQL STRING is compiled. Basically i want to see the text of the SQLSTRING(highlighted in red at the end) variable and instead i get the total characters in within the string and not the text itself. Please help.

DELIMITER$$  
DROP PROCEDURE IF EXISTS `bluerive_db1`.`Result`$$  
CREATE PROCEDURE Result(In\_Scenario\_ID INT, In\_Campaign\_ID INT , In\_Company\_ID INT /_, OUT X TEXT_/)

BEGIN

Declare No\_More\_Info BOOLEAN DEFAULT FALSE;  
Declare EvalName VARCHAR(20);  
Declare EvalID INT;  
Declare SQLSTRING VARCHAR(4000);

/_SET In\_Scenario\_ID = 1, In\_Campaign\_ID = 1, In\_Company\_ID = 380;_/

/\* Select Only The Correct Names and ID’s From The Evaluator Table which Belong to the Scenario, Campaign and Company\*/

DECLARE The\_Cursor CURSOR FOR  
SELECT Distinct Evaluator.Evaluator\_Name, Evaluator.Evaluator\_ID From Score\_Card  
Left Join Evaluator on Evaluator.Evaluator\_ID = Score\_Card.Evaluator\_ID  
Left Join Metric on Metric.Metric\_ID = Score\_Card.Metric\_ID  
Where Metric.Scenario\_ID = In\_Scenario\_ID and Score\_Card.Campaign\_ID = In\_Campaign\_ID and Score\_Card.Company\_ID = In\_Company\_ID;

/_Create a loop by using a cursor to create the correct amount of columns for the Evaluators_/

DECLARE CONTINUE HANDLER FOR NOT FOUND SET No\_More\_Info := TRUE;

/_Write a string output_/

SET SQLSTRING := 'Select A.Metric\_Name as Metric\_Name ';

OPEN The\_Cursor;  
The\_Loop: LOOP  
FETCH The\_Cursor Into EvalName, EvalID;

SET SQLSTRING := SQLSTRING +  
’ ,(Select Distinct Score\_Value From Score\_Card Where Campaign\_ID = A.Campaign\_ID  
and Company\_ID = A.Company\_ID and Evaluator\_ID = ’ + EvalID + ’ and Metric\_ID = A.Metric\_ID ) as ’ + EvalName;

```
        IF No_More_Info THEN
          CLOSE The_Cursor;
            LEAVE The_Loop;
        END IF;
      END LOOP The_Loop;

```

SET SQLSTRING := SQLSTRING + ’ FROM (Select Distinct Score\_Card.Metric\_ID, Metric.Metric\_Name, Campaign\_ID, Company\_ID From Score\_Card  
Inner Join Metric on Metric.Metric\_ID = Score\_Card.Metric\_ID  
Where Campaign\_ID = ’ + In\_Campaign\_ID +’ and Company\_ID = ’ + In\_Company\_ID + ’ and Metric.Scenario\_ID = ’ + In\_Scenario\_ID +  
’ Order by 1) as A ';

[COLOR=Red] **SELECT SQLSTRING;** [/COLOR]

END$$  
DELIMITER ;
