簡體   English   中英

使用存儲過程將數據從一個表復制到另一個表

[英]copy data from one table to another using stored procedure

我想將數據從B_Table復制到A_Table數據

然后最后刪除B_Table數據

我剛剛創建了以下

CREATE PROCEDURE [dbo].[Copy_ProductStatistics]

  (@Product_ID nvarchar, @ProductName nvarchar,@CreatedDate datetime)

AS

BEGIN
        INSERT INTO A_Table(Product_ID, ProductName,CreatedDate)

        SELECT Product_ID, ProductName,CreatedDate
        FROM B_Table
        WHERE (Product_ID = @Product_ID AND ProductName = @ProductName AND CreatedDate = @CreatedDate

        DELETE FROM  B_Table
END

然后我像下面這樣稱呼它

    [HttpGet]
    public ActionResult Copy_DatatoProductStatistics()
    {
        var incomplete_product_result = db.Database.SqlQuery<ProductStatistics>("Copy_ProductStatistics");

        return RedirectToAction("FileUpload", "FileUpload");
    }

這沒有彈出任何錯誤似乎, stored procedure問題

這是一個使用參數調用存儲過程的示例。 sp不返回任何數據: (ctx.ExecuteCommand是Database.ExecuteSqlCommand方法的包裝)

    const string sql = "DeleteVersion @pVersiontId";
    using (IContext ctx = DI.Container.Resolve<IContext>()) {
        try {
            ctx.ExecuteCommand(sql, new SqlParameter("@pVersiontId", versionId));
        } catch (SqlException ex) {
            LoggerFactory.CreateLog().LogError(String.Format(Resources.CouldNotDeleteDeVersion, versionId), ex);
            throw new CannotDeleteVersionExcpetion(String.Format(Resources.CouldNotDeleteDeVersion, versionId), ex);
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM