|
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 triedcreate 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) ) asdeclare @status intexecute @status = BaseExists @MacAddressif @status = -100Begin insert into Base (BSerialNum, BMacAddress, IpAddress, Location, ColorCode, Channel,BDateRegistered, SysName) Values (@SerialNum, @MacAddress, @IpAddress, @Location, @ColorCode,@Channel, @Date, @SysName) return -100EndelseBegin Update Base set IPAddress = @IpAddress, Location = @Location, ColorCode = @ColorCode, Channel = @Channel, BDateRegistered = @Date, SysName = @SysName where BMacAddress = @MacAddress return -200EndAs 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 followingsprintf ((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." |
|