亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

求sql存儲過程怎么修改

求sql存儲過程怎么修改

楊__羊羊 2018-12-07 09:25:06
功能是根據ProductsId從Base_Gx_ProductsInfo表中獲取ProductsTypeId,Sales的值,然后根據獲取到的ProductsTypeId,在從表Base_SmallTypeInfo獲取SaleValue進行比較。如果Sales小于SaleValue則更新表update Base_Gx_ProductsInfo set Status= 3 ,ProcessStatus=1? Where ProductsId=@ProductsId否則更新為 Status= 1 ,ProcessStatus=1,然后再比較下面的ALTER PROCEDURE [dbo].[Check_productStatus]@ProductsId int,@out_msg nvarchar(20) output,@out_result int output?AS? ?BEGIN? /*變量定義*/? DECLARE? @VCOUNT INT,? ? @VCARDSN INT,? ? @VOPCOUNT INT,? ? @VProductsTypeId INT,? @VSales VARCHAR(30),@VSaleValue VARCHAR(30),? ? @VEMPCODE VARCHAR(30)? ?SELECT ProductsTypeId,Sales? into VProductsTypeIdFROM [Base_Gx_ProductsInfo]WHERE ProductsId=@ProductsId;? SELECT SaleValue? into VSaleValueFROM Base_SmallTypeInfoWHERE ProductsTypeId=@VProductsTypeId;IF convert(int,@VSales)>convert(int,@VSaleValue)BEGIN? update Base_Gx_ProductsInfo set Status= 3 ,ProcessStatus=1? Where ProductsId=@ProductsId? SET @out_msg = '更新狀態成功'? SET @out_result = 101? ?ENDElseSELECT @VCOUNT = ISNULL(COUNT_BIG(*), 0)FROM [Base_Gx_ProductsInfo]WHERE ProductsId=@ProductsId and ProcessStatus<>1;?if @VCOUNT > 0? BEGIN? ? update Base_Gx_ProductsInfo set Status= 3 ,ProcessStatus=1? Where ProductsId=@ProductsIdupdate Base_Gx_ProductsInfo set Base_Gx_ProductsInfo.ProcessStatus=1, Base_Gx_ProductsInfo.Status = case when b.ProductsName is null then 0 else 1 end from Base_Gx_ProductsInfo as ainner join Base_CustomerInfo as c on a.customerId=c.customerIdleft join Base_State_ProductsInfo as b on a.ProductsName=b.ProductsName and c.CompanyName=b.CompanyName? Where A.ProductsId=@ProductsId? SET @out_msg = '提交成功!'? SET @out_result = 100 ? ? ENDELSE?BEGIN? SET @out_msg = '未找到記錄或產品已提交過!'? SET @out_result = 99? ?ENDEnd
查看完整描述

2 回答

?
喵喔喔

TA貢獻1735條經驗 獲得超5個贊

alter proc check_productstate
@productsId int
?
as
begin
declare @sales int,
declare @salesvalue int

select productsTypeId,@sales=Sales from [Base_Gx_ProductsInfo]
where productsTypeId=@productsId

select @salesvalue=SaleValue from [@salesvalue ]? where? '條件'

if @sales < @salesvalue
?begin
??? update Base_Gx_ProductsInfo set Status=3,ProcessStatus=1
???? Where ProductsId=@ProductsId
???????? if(@@error<>0) goto cleanup
?end
else
?begin
??? update Base_Gx_ProductsInfo set Status=1,ProcessStatus=1
???? Where ProductsId=@ProductsId
???????? if(@@error<>0) goto cleanup
?end

?
if( @@error <> 0 ) goto cleanup
else commit transaction
end
---------------------
cleanup:
?rellback transaction

?

呵呵,亂寫一下,不知道對你有沒有用。。

查看完整回答
反對 回復 2019-01-07
  • 2 回答
  • 0 關注
  • 519 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號