sql命令没有返回预期的答案 [英] sql Command not Returning Expected answer
本文介绍了sql命令没有返回预期的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
更改 过程 AddStockToBranch
@ ItemCode varchar ( 200 )= NULL,
@ BranchName varchar ( 150 )= NULL,
@ Qty int = NULL ,
@ TotalUsed int = NULL
AS
如果 存在(选择 ItemCode 来自 StockInBranches
where ItemCode = @ ItemCode 和 BranchName = @ BranchName )
begin
更新 StockInBranches SET 数量= @Qty +
(选择数量来自 StockInBranches 其中 ItemCode = @ ItemCode 和 BranchName = @ BranchName )其中
ItemCode = @ ItemCode 和 BranchName = @ BranchName
end
否则
开始
插入 向跨度> StockInBranches(ItemCode,BranchName,Qty,TotalUsed)
values ( @ ItemCode , @ BranchName , @ Qty , @ TotalUsed )
end
此程序未返回预期结果,数量值为总是给零,即使我将值传递给@Qty。请检查代码我在那里犯了什么错误。
解决方案
你实际上是插入或更新一些记录符合你的条件,但你没有返回任何东西。
如果你想返回@Qty
,那么最后一个SELECT
it。
SELECT < span class =code-sdkkeyword> @ Qty
试试..
开始
如果 @Qty null
开始
设置 @ Qty = 0
开始
更新 StockInBranches SET 数量= @ Qty +
isnull(Cast(选择数量来自 StockInBranches 其中 ItemCode = @ ItemCode 和 BranchName = @ BranchName ) as int ),< span class =code-digit> 0 )其中
ItemCode = @ ItemCode 和 BranchName = @ BranchName
end
结束跨度>
Alter Procedure AddStockToBranch
@ItemCode varchar(200)=NULL,
@BranchName varchar(150)=NULL,
@Qty int = NULL,
@TotalUsed int = NULL
AS
if exists(select ItemCode from StockInBranches
where ItemCode = @ItemCode and BranchName = @BranchName)
begin
UPDATE StockInBranches SET Qty = @Qty +
(Select Qty from StockInBranches Where ItemCode = @ItemCode and BranchName = @BranchName) Where
ItemCode=@ItemCode and BranchName = @BranchName
end
else
begin
Insert Into StockInBranches(ItemCode,BranchName,Qty,TotalUsed)
values (@ItemCode,@BranchName,@Qty,@TotalUsed)
end
this procedure not returning expected result , Qty value is always giving zero even I pass the value to @Qty. please check the code what I did the mistake there.
解决方案
You are actually Inserting or Updating some records matching your conditions, but you are not returning anything.
If you want to return@Qty
, then at the lastSELECT
it.
SELECT @Qty
try..
Begin if @Qty is null begin set @Qty=0 begin UPDATE StockInBranches SET Qty = @Qty + isnull(Cast(Select Qty from StockInBranches Where ItemCode = @ItemCode and BranchName = @BranchName) as int),0) Where ItemCode=@ItemCode and BranchName = @BranchName end End
这篇关于sql命令没有返回预期的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文