[英]How to assign values to variables in SQL stored procedure?
我正在嘗試創建一個變量,該變量指示庫存中剩余多少產品,但是在Visual Studio中,它會警告將多個值分配給varialvel @quantityProduct,有人可以幫助我嗎?
BEGIN
Declare @quantityProduct int
Select * from tbStore
Where name = @product
Set @quantityProduct = (select (quantity) from tbStore)
END
可能是這樣:
Declare @quantityProduct int
Select @quantityProduct = quantity
From tbStore
Where name = @product
我認為這就是您想要做的。
BEGIN
Declare @quantityProduct int
Select @quantityProduct = quantity
from tbStore
Where name = @product
END
您將其聲明為int。 您的查詢可能返回多個值,因此結果無法存儲在此變量中。 將查詢限制為僅返回一個值或將變量聲明為int表。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.