sproc没有设置声明变量的值? [英] sproc not setting value for declared variable?

查看:80
本文介绍了sproc没有设置声明变量的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我声明了一个变量并希望通过选择查询设置它的值。



i有一张表:



fileNameGenerator

______________________

(pk)fileSymbol | bc



这是我的sp:



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:

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





出于某种原因,这是我得到的输出...



运行[dbo]。[ bcSymbol](@ bc = 8.550000000000000)。



没有行影响。

(0行返回)

@RETURN_VALUE = 0

完成运行[dbo]。[tempFileName]。



i不明白为什么我不是得到正确的符号。我从表本身复制了bc值。输出应该是一个1根据table.s



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

推荐答案

你使用 RETURN 语句没有任何值。如果在RETURN上没有指定值,则存储过程返回值0.

来源:使用RETURN [ ^ ]



我建议你阅读这篇文章:从存储过程中返回数据 [ ^ ]。有两种方法可以从SP返回数据。



另一种方法是返回记录集:

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:
ALTER PROCEDURE bcSymbol
       @bc decimal(18,15)
AS
BEGIN
SELECT fileSymbol
FROM fileNameGenerator
WHERE bc = @bc
END


这篇关于sproc没有设置声明变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆