0
我有沒有主鍵和外鍵表名錶被C_User_Credentials我附上截圖請到通過更多細節 如何插入從自動生成的數據和已經創建的數據
我寫了一個存儲過程的代碼是
ALTER PROCEDURE [dbo].[usp_Duplicate]
@inputkey NVARCHAR(36)
, @Formkey NVARCHAR(36) output
AS
BEGIN
DECLARE @Form NVARCHAR(36)
SET @Form = NEWID()
SELECT *
INTO #s
FROM [2290_Form]
WHERE PK_2290F_key = @inputkey
INSERT INTO [2290_Form]
VALUES (@Form, (SELECT #s.FK_C_B_key FROM #s), (SELECT #s.is_vin_correction FROM #s), (SELECT #s.is_amendment FROM #s), (SELECT #s.amendment_category FROM #s), (SELECT #s.is_final_return FROM #s), (SELECT #s.first_used_month FROM #s), (SELECT DATEPART(year, GETDATE()) FROM #s), (SELECT #s.tax_amt FROM #s), (SELECT #s.additional_amt FROM #s), (SELECT #s.credit_amt FROM #s), (SELECT #s.payment_mode FROM #s), (SELECT #s.consent_tag FROM #s), (SELECT #s.status FROM #s), GETDATE(), NULL)
SELECT NEWID() AS Pk
, @Form AS fk
, vin
, category
, is_logging
, is_agricultural
, is_mileage_exceed
, weight_current
, weight_old
, credit_reason
, buyer
, effective_date
, tax_amt
, GETDATE() AS crn_dt
, NULL AS upd_dt
INTO #v
FROM [2290_Vehicles]
WHERE FK_2290_F_key = @inputkey
INSERT INTO [2290_Vehicles] (PK_2290_V_key, FK_2290_F_key, vin, category, is_logging, is_agricultural, is_mileage_exceed, weight_current, weight_old, credit_reason, buyer, effective_date, tax_amt, crn_dt, upd_dt)
SELECT * FROM #v
SET @Formkey = @Form
END
在上面的存儲過程一種形式鍵將generate.problem是生成表單關鍵我需要合併CFK_C_UP_key的幫助來自C_User_Credentials表的列和生成的form_key都在一張新表中怎麼辦請幫幫我