Unix Technical Forum

DESPERATE help needed....

This is a discussion on DESPERATE help needed.... within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello all, I am a total newbie to SQL. I created this sp and then with C++, called it. ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 04:12 AM
Ralph Krausse
 
Posts: n/a
Default DESPERATE help needed....

Hello all,

I am a total newbie to SQL. I created this sp and then with C++,
called it. My return value was 100 (which it was)

CREATE PROCEDURE sp_StoreIPs
@IPSource varchar(16),
@IPTarget varchar(16),
@TimeDate varchar(20),
@Name varchar(250)
as
declare @iReturn int
Set @iReturn = 100
return @iReturn
GO

Then when I added a INSERT statement like ...


CREATE PROCEDURE sp_StoreIPs
@IPSource varchar(16),
@IPTarget varchar(16),
@TimeDate varchar(20),
@Name varchar(250)
as
declare @iReturn int
Insert into LookUP (IPSource, IPTarget,TimeDate, Name) Values
(@IPSource,@IPTarget,@TimeDate,@Name)
Set @iReturn = 100
return @iReturn
GO


My return value was 0. I am assuming the the INSERT statement is
returning the 0 but how can I get around this?


Thanks
Ralph Krausse
www.consiliumsoft.com
Use the START button? Then you need CSFastRunII...
A new kind of application launcher integrated in the taskbar!
ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 04:12 AM
Craig Kelly
 
Posts: n/a
Default Re: DESPERATE help needed....

"Ralph Krausse" wrote:

<snip>

> CREATE PROCEDURE sp_StoreIPs
> @IPSource varchar(16),
> @IPTarget varchar(16),
> @TimeDate varchar(20),
> @Name varchar(250)
> as
> declare @iReturn int
> Insert into LookUP (IPSource, IPTarget,TimeDate, Name) Values
> (@IPSource,@IPTarget,@TimeDate,@Name)
> Set @iReturn = 100
> return @iReturn
> GO
>
>
> My return value was 0. I am assuming the the INSERT statement is
> returning the 0 but how can I get around this?


<snip>

Ralph,

I think you're half correct: an insert can return a message about records
affected... but I don't know why that would affect the return value unless
the insert failed: are you checking to insure successful execution? My
guess would be that the INSERT is failing.

In any event, to suppress the record count coming back as a message, you can
use SET NOCOUNT ON/OFF:

CREATE PROCEDURE blah
AS

SET NOCOUNT ON

INSERT SomeTable (fld) VALUES ('a')

SET NOCOUNT OFF

RETURN 100
GO

And the NOCOUNT setting can be handy even if this isn't your problem: it's
always nice to eliminate unnecessary network chitchat

Craig


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 04:12 AM
Erland Sommarskog
 
Posts: n/a
Default Re: DESPERATE help needed....

[posted and mailed, please reply in news]

Ralph Krausse (gordingin@consiliumsoft.com) writes:
> I am a total newbie to SQL. I created this sp and then with C++,
> called it. My return value was 100 (which it was)


And what API did you use to call the procedure from C++?

> CREATE PROCEDURE sp_StoreIPs


Don't use the sp_ prefix for the names of stored procedure. This prefix
is reserved for system procedures, and SQL Server first looks for
procedures with this prefix in the master database.

> Then when I added a INSERT statement like ...
>...
> My return value was 0. I am assuming the the INSERT statement is
> returning the 0 but how can I get around this?


As Craig said, the INSERT statement generates a kind of result set to
inform of the number of rows consumed. If you don't get that result
set, you will not get the return value, nor the value of output parameter,
since these are not availble until all result sets have been consumed.

Since I don't know which API you are using, I cannot say which methods you
should use, but you should always make it a habit to fetch all result set.

SET NOCOUNT ON, which Craig suggested, is a very good idea, if you are
not interested in these record counts, since they cause extra round-trips
to the server. However, result sets may appear of other reasons, for
instance a trigger with a SELECT statement in it. (Which is poor practice,
but accidents happens.)

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:01 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com