使用存储过程将数据从一个表复制到另一个表
本文关键字:一个 复制 另一个 存储过程 数据 | 更新日期: 2023-09-27 18:31:57
我想将数据复制到A_Table
数据B_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);
}
}