我已经创建了一个简单的存储过程来更新我的Sample_TAG_NUMBERTEST
表,但是我需要它来使用ItemCode
和&同时从另一个表PartItem
获取SOLine
。 SONbr
进行查询,但我不知道如何编写。
我需要做的第二件事是当我的StatusCode
列为N001
时,我的DESC
列会自动插入NEW ORDER
数据值,PR002
我的DESC
列将成为Progress
。
我该怎么做?提前谢谢。
ALTER PROCEDURE [dbo].[SampleTagNumberUpdate]
@sONbr nvarchar(50) = NULL,
@SOLine nvarchar(50) = NULL,
@SerialNbr nvarchar(50) = NULL,
@StatusCode nvarchar(50) = NULL,
@PackType nvarchar(50) = NULL,
@PalletID nvarchar(50) = NULL,
@PackingListNo nvarchar(50) = NULL,
@ItemCode nvarchar(50) = NULL,
@CrDateTime nvarchar(50) = NULL,
@CrUserID nvarchar(50) = NULL,
@return nvarchar(50) = NULL OUTPUT
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS(SELECT sONbr , SOLine
FROM [SampleSystem].[dbo].[Sample_TAG_NUMBERTEST]
WHERE sONbr = @sONbr AND SOLine = @SOLine)
BEGIN
UPDATE [SampleSystem].[dbo].[Sample_TAG_NUMBERTEST]
SET SerialNbr = @SerialNbr
,StatusCode = @StatusCode
,PackType = @PackType
,PalletID = @PalletID
,PackingListNo = @PackingListNo
,ItemCode = @ItemCode
,LastUpdDateTime = GETDATE()
,LastUpdUserID = @CrUserID
WHERE sONbr = @sONbr AND SOLine = @SOLine
IF @@ERROR <> 0
Set @Return = 'UPDATE FAILED'
ELSE
Set @Return = 'UPDATE SUCCESSFULLY'
END
ELSE
BEGIN
INSERT INTO [SampleSystem].[dbo].[Sample_TAG_NUMBERTEST](SONbr, SOLine, SerialNbr
,StatusCode
,PackType
,PalletID
,PackingListNo
,ItemCode
,CrDateTime
,CrUserID)
VALUES(@sONbr, @SOLine, @SerialNbr, @StatusCode, @PackType
,@PalletID
,@PackingListNo
,@ItemCode
,GETDATE()
,@CrUserID)
IF @@ERROR <> 0
Set @Return = 'INSERT DATA FAILED'
ELSE
Set @Return = 'INSERT DATA SUCCESSFULLY'
END
END
答案 0 :(得分:0)
我相信我已经为以下两个问题提供了一个例子:
UPDATE T
SET ItemCode = (SELECT PI.ItemCode FROM PartItem AS PI WHERE PI.SO = @SO AND PI.SO_LINE = @SO_LINE),
DESC = CASE @StatusCode WHEN 'N001' THEN 'NEW ORDER'
ELSE CASE @StatusCode WHEN 'PR002' THEN 'PROGRESS' ELSE '' END
END,
<other columns here...>
FROM SAMPLE_TAG_NUMBERTEST AS T