Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Passing return codes from a stored procedure back to a C application

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-08-19 : 18:35:13
Rod writes "I have created a Stored Procedure in a Sql Server 7.0 database.
The stored procedure takes in several parameters and either adds the entry to the table if it doesn't exist or it updates the entry if it already exists.

I then call the Stored procedure from a c application. I would like to pass back a return code indicating whether the record was added or updated. Can this be done.


Here is what I tried

create procedure AddBase (@SerialNum int, @MacAddress char (12),@IpAddress char (20),@Location varchar (80), @ColorCode char (10), @Channel char (10),@Date char (40),@SysName varchar (80) ) as

declare @status int
execute @status = BaseExists @MacAddress
if @status = -100
Begin

insert into Base (BSerialNum, BMacAddress, IpAddress,
Location, ColorCode, Channel,BDateRegistered, SysName)
Values (@SerialNum, @MacAddress, @IpAddress, @Location,
@ColorCode,@Channel, @Date, @SysName)
return -100

End

else
Begin

Update Base set IPAddress = @IpAddress, Location =
@Location, ColorCode = @ColorCode,
Channel = @Channel, BDateRegistered = @Date, SysName =
@SysName where BMacAddress = @MacAddress
return -200

End

As you can see I want -100 returned if the Base was added and
-200 if the Base was updated.


The C code looks like the following
sprintf ((char *)SQLCommand, "execute AddBase
1,'0:0:0:1','0.0.0.1','RodsOffice','10', '15', '08/13/01',
'TestBase'");
V_OD_err = SQLExecDirect (hstmt, SQLCommand, strlen ((char *)SQLCommand));

But SQLExecDirect always returns SQL_SUCCESS (0). I wouldn't even care if I got back SQL_SUCCESS_WITH_INFO (1). As long as I could get a return code to indicate which path of the stored procedure it took.

"
   

- Advertisement -