Solved

Don´t return value

Posted on 2010-11-28
5
768 Views
Last Modified: 2012-05-10
Hi Sir, I try the same example, but I have problem with return value,does not return anything, I use or connect my PowerBuilder aplications to the SQL Server 2008, across ODBC Connections, do you have some suggestion?, I appreciate your help..!!!!
0
Comment
Question by:digistarsystem
  • 3
  • 2
5 Comments
 
LVL 3

Expert Comment

by:kotukunui
Comment Utility
Are you using a Datawindow connected to the stored procedure or are you using embedded SQL in PowerScript?

If a datawindow, what value to you get returned by the retrieve() function call?

If inline SQL, what value is in sqlca.sqlcode when the stored procedure is called?

Post some example code of what you are doing and any detail about configuration that you think is relevant and I'll see if I can diagnose the issue.
0
 

Author Comment

by:digistarsystem
Comment Utility
Hello Kotuunui, I use embedded SQL, the sqlca.sqlcode return a 0, but the SP don´t return anythins value, above I describe the SP and the script called a SP:

***********************
Stored Procedure
***********************


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[sp_getkeymax]
      @table_name nvarchar(500),@column_name nvarchar(500),@keymax nvarchar(500) OUTPUT
WITH EXECUTE AS CALLER
AS
BEGIN

  SET NOCOUNT ON;

  DECLARE @nombre_tabla nvarchar(500), @nombre_columna nvarchar(500),  
            @SQLString nvarchar(500),@SQLString_Incidente nvarchar(500),
            @Parametros nvarchar(500)

  SELECT @nombre_columna = @column_name
  SELECT @nombre_tabla = @table_name
 
  SET @SQLString = 'select @keymax = max('+@nombre_columna+') from '+@nombre_tabla
  SET @Parametros = N'@keymax int OUTPUT'
  EXEC sp_executesql @SQLString,@Parametros,@keymax = @keymax OUTPUT
  SET @SQLString = 'Update Bitacora_GetKeyMax Set nombre_tabla = '''+@nombre_tabla+''',nombre_columna = '''+@nombre_columna +''',valor_columna = '''+@keymax+''''

 SET @Parametros = N'@keymax int OUTPUT'
 EXEC sp_executesql @SQLString ,@Parametros,@keymax = @keymax OUTPUT

return @keymax
END

*********************
Calling a SP
*********************

string key_max

DECLARE  sp_getmaxkey_procedure PROCEDURE  FOR sp_getmaxkey  @table_name = "articulos",@colum_name = "codigo_articulo",@maxkey = key_max  USING sqlca;

EXECUTE sp_getmaxkey_procedure;

FETCH sp_getmaxkey_procedure INTO :key_max;

0
 
LVL 3

Expert Comment

by:kotukunui
Comment Utility
I have read in other articles that PowerBuidler doesn't like OUTPUT paramters in embedded SQL in this format

Open the POwerBuilder Help and go to the section called "Dynamic SQL Format 4 SQL statement
" and look at the examples

Example 3  This example is for a stored procedure with a return value for a SQL Native Client (SNC) connection:

integer var1, ReturnVal

string var2

 

PREPARE SQLSA FROM  "execute @rc = myproc @parm1=?, @parm2=? OUTPUT ";

 

DESCRIBE SQLSA INTO SQLDA ;

 

DECLARE my_proc DYNAMIC PROCEDURE FOR SQLSA ;

 

SetDynamicParm(SQLDA, 1, var1)

SetDynamicParm(SQLDA, 2, var2)

 

EXECUTE DYNAMIC my_proc USING DESCRIPTOR SQLDA ;

 

//fetch result set

. . .

 

//fetch return value and output parameter

FETCH my_proc USING DESCRIPTOR SQLDA ;

 

//get return value

CHOOSE CASE SQLDA.OutParmType[1]

CASE TypeInteger!

   rc =  GetDynamicNumber(SQLDA, 1)

CASE TypeLong!

   rc =  GetDynamicNumber(SQLDA, 1)

CASE TypeString!

   Var2 = GetDynamicString(SQLDA, 1)

END CHOOSE

 

//get output value

 

CHOOSE CASE SQLDA.OutParmType[2]

CASE TypeString!

   Var2 = GetDynamicString(SQLDA, 2)

CASE TypeInteger!

   rc =  GetDynamicNumber(SQLDA, 2)

CASE TypeLong!

   rc =  GetDynamicNumber(SQLDA, 2)

END CHOOSE

 

CLOSE my_proc ;

You will probably need to use this format rather than the Format 1 as per your example. I read a PB bug list entry saying that this had been fixed but it appears not...
0
 

Accepted Solution

by:
digistarsystem earned 0 total points
Comment Utility
Thank you Kutukuni, with the concept and your references, I can solve the problem.

Regards,
0
 

Author Closing Comment

by:digistarsystem
Comment Utility
The sulotions suply, is part of the global solutions.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
commonTwo  challenge 63 98
File.WriteAllLines problem at random C# ASP.NET 6 53
pairs challenge 5 44
C Programming - If Statement 8 47
This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now