Solved

Don´t return value

Posted on 2010-11-28
5
786 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
ID: 34227658
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
ID: 34227789
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
ID: 34227897
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
ID: 34260668
Thank you Kutukuni, with the concept and your references, I can solve the problem.

Regards,
0
 

Author Closing Comment

by:digistarsystem
ID: 34289910
The sulotions suply, is part of the global solutions.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

910 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

22 Experts available now in Live!

Get 1:1 Help Now