?
Solved

@RETURN_VALUE ??

Posted on 2003-03-15
6
Medium Priority
?
253 Views
Last Modified: 2009-12-16
Hi,

I have got the following SQL stroerd procedure below. Basically the query should return either a 1 or a 0, which it does, the only problem is that it returns it in a new column called "ReturnStatus", what i need to do is return the integer result in the actual @RETURN_VALUE.

Does anybody know how to do this ?

Thanks

Rob

--------------------------Stored Procedure Below------------------------------------

CREATE PROCEDURE dbo.ValidateReservation
(
     @Computer_name As VarChar(50),
     @Res_start_time As DateTime,
     @Res_end_time As DateTime
)
AS

Declare @ReturnStatus As Int

Select Computer_name,

Max ( Case When ( @Res_start_time >= Session_start_time) And  ( @Res_start_time < Session_end_time ) Or  ( @Res_start_time > Session_start_time ) And ( @Res_start_time < Session_end_time )
Or ( @Res_end_time > Session_start_time ) And ( @Res_end_time <= session_end_time ) Then 1 Else 0 End ) As ReturnStatus

From Session
Where @Computer_name = Computer_name

group by computer_name
GO
0
Comment
Question by:Rob_2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 5

Expert Comment

by:JimV_ATL
ID: 8142862
This should work:


CREATE PROCEDURE dbo.ValidateReservation
(
    @Computer_name As VarChar(50),
    @Res_start_time As DateTime,
    @Res_end_time As DateTime,
    @ReturnStatus As Int Output
)
AS



Select
@ReturnStatus = Max (
     Case
     When
     ( @Res_start_time >= Session_start_time)
     And  ( @Res_start_time < Session_end_time )
     Or  ( @Res_start_time > Session_start_time )
     And ( @Res_start_time < Session_end_time )
     Or ( @Res_end_time > Session_start_time )
     And ( @Res_end_time <= session_end_time )
     Then 1 Else 0 End )

From Session
Where @Computer_name = Computer_name

group by computer_name

**********************************************************

When you go to call the procedure, you'll need to specify output after @ReturnStatus, e.g.

exec dbo.ValidateReservation @Computer_name, @Res_start_time, @Res_end_time, @ReturnStatus Output
)
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 8143005
Make the following change:

CREATE PROCEDURE dbo.ValidateReservation
(
    @Computer_name As VarChar(50),
    @Res_start_time As DateTime,
    @Res_end_time As DateTime
)
AS

Declare @ReturnStatus As Int

Select Computer_name,

Max ( Case When ( @Res_start_time >= Session_start_time) And  ( @Res_start_time < Session_end_time ) Or  ( @Res_start_time > Session_start_time ) And ( @Res_start_time < Session_end_time )
Or ( @Res_end_time > Session_start_time ) And ( @Res_end_time <= session_end_time ) Then 1 Else 0 End ) As ReturnStatus

From Session
Where @Computer_name = Computer_name

group by computer_name

RETURN @ReturnStatus                  -- Add this line

GO

Anthony
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 8143010
Actually my code is not correct, it should be:
CREATE PROCEDURE dbo.ValidateReservation
(
   @Computer_name As VarChar(50),
   @Res_start_time As DateTime,
   @Res_end_time As DateTime
)
AS

Declare @ReturnStatus As Int

Select @ReturnStatus =
Max ( Case When ( @Res_start_time >= Session_start_time) And  ( @Res_start_time < Session_end_time ) Or  ( @Res_start_time > Session_start_time ) And ( @Res_start_time < Session_end_time )
Or ( @Res_end_time > Session_start_time ) And ( @Res_end_time <= session_end_time ) Then 1 Else 0 End )

From Session
Where @Computer_name = Computer_name

group by computer_name

RETURN @ReturnStatus                  -- Add this line

GO
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:Rob_2002
ID: 8143667
Hi,

Thanks for your soloutions, they both work. I'm going to use the one from AcPerkin's because it returns the value into the @RETURN_VALUE, which is what I wanted. I would really like to split the points up, do you know ho to do that? I feel that you both deserve some for your excellence :)

Thanks a lot you are both brilliant !!

Best Wishes Rob
0
 
LVL 5

Expert Comment

by:JimV_ATL
ID: 8144147
Thanks for your thoughtfulness.  Typically, in this case, one would post a question with additional (consolation) points with the title "Points for JimV_ATL" or whomever.  It's not necessary.  It's not necessary, though.

0
 

Author Comment

by:Rob_2002
ID: 8144184
Hi JimV ATL,

You have convinced me :)

I've posted another question with the subject as you've given. Please accept it and the points are yours

Regards

Rob
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

762 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