Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

returning an interger 1

Status
Not open for further replies.

copeZero

Programmer
Aug 31, 2007
46
CA
Hi i can't seem to get a value from this, any suggestions


DECLARE @Random int;
DECLARE @Upper int;
DECLARE @Lower int

SET @Lower = 100
SET @Upper = 150
SELECT @Random = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)

RETURN
GO
 
Code:
DECLARE @Random int;
DECLARE @Upper int;
DECLARE @Lower int

SET @Lower = 100
SET @Upper = 150
SELECT @Random = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)
SELECT @Random

or inside a proc if you want to use the return statement

Code:
DECLARE @Random int;
DECLARE @Upper int;
DECLARE @Lower int

SET @Lower = 100
SET @Upper = 150
SELECT @Random = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)
RETURN @Random

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
tried the proc method, actually tried it prior to posting here. no luck with it. this is the actual proc:

Code:
CREATE PROCEDURE dbo.sp_Temp2
(
@pass nvarchar(40),
@ques nvarchar(100),
@MID int,
@answ nvarchar(80)
)
AS
SET NOCOUNT ON

UPDATE [_Info] SET isTemp=0, pw=@pass, sQ=@ques, sA=@answ 
WHERE
MID=@MID

DECLARE @Random int;
DECLARE @Upper int;
DECLARE @Lower int

SET @Lower = 100
SET @Upper = 150
SELECT @Random = Round(((@Upper - @Lower -1) * Rand() + @Lower), 0)

RETURN
GO

I keep getting a null value returned . Any ideas? Thanks
 
forgot to mention using sql2k

thanks again
 
sorry for the wrong display i am returning

RETURN @Random

i'm actually doing this in a different procedure then the one i displayed, a more stripped down version, still no luck.
 
I have a similar problem I am trying to return an integer
<CODE>
ALTER PROC [dbo].[sp_CheckIDExists]
(
@id varchar(30),
@RETURNVALUE int OUTPUT
)
AS
If (@id) Is NULL return 1

If EXISTS(SELECT ID FROM dbo.v_CI_DRIVERINFO WHERE ID= @id)
@RETURNVALUE = 0
Else
@RETURNVALUE = 1

return

</CODE>

I am getting error "Line 10
Incorrect syntax near '@RETURNVALUE'."
Any help appreciated, it's probably something silly that I am over looking.

thanks.

 
To use code blocks, use square brackets.

[ignore]
Code:
Your Code Here
[/ignore]

To fix your procedure, you need to SET the value, like this...

Code:
ALTER PROC [dbo].[sp_CheckIDExists]
(
    @id    varchar(30),
    @RETURNVALUE int OUTPUT
)
AS
If (@id) Is NULL return 1

If EXISTS(SELECT ID FROM dbo.v_CI_DRIVERINFO WHERE ID= @id)
    [!]SET[/!] @RETURNVALUE = 0
Else
    [!]SET[/!] @RETURNVALUE = 1

return

-George

"the screen with the little boxes in the window." - Moron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top