Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i declared a variable and want to set it's value by way of a select query.

i have a table:

fileNameGenerator
______________________
(pk)fileSymbol | bc

here's my sp:

SQL
alter procedure bcSymbol
(
@bc decimal(18,15)
)
AS
/* SET NOCOUNT ON */
Declare @bcSymbol varchar(50)
Select @bcSymbol = (SELECT fileSymbol From fileNameGenerator WHERE bc = @bc)
RETURN


for some reason, this is the output i get...

Running [dbo].[bcSymbol] ( @bc = 8.550000000000000 ).

No rows affected.
(0 row(s) returned)
@RETURN_VALUE = 0
Finished running [dbo].[tempFileName].

i don't understand why i'm not getting the proper symbol back. i copied the bc value in from the table itself. the output should have been a 1 according to the table.s
Posted
Comments
pradiprenushe 25-Nov-13 13:29pm    
What is result of this query
SELECT fileSymbol From fileNameGenerator WHERE bc = 8.550000000000000

1 solution

You used RETURN statement without any value. If no value is specified on RETURN, a stored procedure returns the value 0.
Source: Using RETURN[^]

I would suggest you to read this article: Return Data from a Stored Procedure[^]. There are 2 ways to return data from SP.

Another way is to return recordset:
SQL
ALTER PROCEDURE bcSymbol
       @bc decimal(18,15)
AS
BEGIN
SELECT fileSymbol
FROM fileNameGenerator
WHERE bc = @bc
END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900