Welcome! Log In Create A New Profile

Advanced

How to Run a MS SQL Store Procedure and get the Value from it to a Variable

Posted by MPD_For_Life 
How to Run a MS SQL Store Procedure and get the Value from it to a Variable
February 09, 2021 02:32AM
Hello everyone and Thank you in advance for the Help

I have this stored procedure inside a Microsoft Sequel Database which gets me the Date and Time of the Server.

Name of the Procedure: Get_The_Date_And_Time

Structure of the Procedute

CREATE PROCEDURE dbo.Get_The_Date_And_Time
AS
BEGIN
/* Procedure body */
DECLARE @Date_And_Time as date SELECT Date_And_Time = GETDATE();
END


The result of the Procedure if executed is the following:
Under the Column Name "Get_The_Date_And_Time" The result is the Following


2/8/2021 8:10:19 PM <-------- This is the Date and Time of the Server when the stored procedure is Executed

My question is: How can I run this store procedure from within WinDev or WebDev and put the result in a Variable, for Example varServerDate.

I have tried different things HExecuteProcedure() This does not work with ODBC Connection
I Have tried with HExecuteSQLQuery Get errors
I have tried SQLExec got errors too


Nothing works

I would really appreciate it you can give me a hand on this and perhaps a code Example can be provided since I have no clue where to start.

Thank you so Much

Best regards,
Carlos




Edited 2 time(s). Last edit at 02/09/2021 02:43AM by MPD_For_Life.
Re: How to Run a MS SQL Store Procedure and get the Value from it to a Variable
March 20, 2023 10:56PM
Hi we use that all the time. It is not realy complicated. I will see If I can get you some code . I can not copy past as the software is commercial stuff. ok

It is quite easy so no worries . I will get back at you as i will have to look at the source and make a bit of code for you ( none tracable to hou software . Ok


regards

Renko

PS PCSoft help should be able to help you out as well
Ok here goes,

You make a new connection and execute it see below:

datasourcemyprocedure is Data Source

if hopenconnection( your connectionvar) then
Hcanseldeclaration(dsMyProcedure)

IF HExecuteSQLQuery(dsMyProcedure,"MyConnection", hQueryWithoutCorrection, "dbo.sp_yourstored procedure @o_RKey out") THEN

//.o_RKey out is the variable you are gettting out of you sp
the key = dsMyProcedure.o_RKey out

hclose(dsMyprocedure)
Hcloseconnection(your connectionvar
else

end
Re: How to Run a MS SQL Store Procedure and get the Value from it to a Variable
August 22, 2023 12:29PM
Hey there!
If you have any queries about the store procedures of ms sql then you can check in to the official website of ms sql.
Author:

Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: