挿入ストアド プロシージャがあり、ユーザーが送信するパラメーター値に応じて句テーブルを動的に設定したいSELECT
と考えています。
*編集、最初に間違ったコード例を投稿しました。お詫び *
CREATE PROC [spInsertLOG_ReqClone]
(@NewReqID char(8),
@ReqID char(8),
@SiteCode char(3),
@RequestorID char(6),
@CloneFromPo bit)
AS BEGIN
DECLARE @ReqCreatedDate datetime = GetDate()
SET @NewReqID = dbo.fnLOG_ReqIDGenerator(@SiteCode) --Generates New ReqID
INSERT INTO LOG_ReqHeader (
ReqID,
ReqCreatedDate,
RequestDate,
RequiredByDate
)
(SELECT
@NewReqID,
@ReqCreatedDate,
@ReqCreatedDate,
@RequiredByDate
FROM LOG_ReqHeader h
WHERE h.ReqID = @ReqID )
INSERT INTO LOG_ReqLineItems
(ReqID,
QtyOrdered,
UI,
PartNumber,
Nomenclature )
If @CloneFromPO = 0 -- Use line items intially entered in ReqLineITems table
BEGIN
(SELECT
@NewReqID,
l.QtyOrdered,
l.UI,
l.PartNumber,
l.Nomenclature
FROM ReqLineItems l
WHERE l.ReqID = @ReqID)
END
If @CloneFromPO = 1 -- Use line items after PO was issued from PO table
Begin
(SELECT
@NewReqID,
l.Qty_Ord,
l.UnitOfIssue,
l.Part_Number,
l.Item_Desc
FROM PO_LineItems l
WHERE l.ReqID = @ReqID)
END
END