使用存储过程在SQL Server 2005中将多个记录插入相同的字段 [英] Insert Multiple Records Into Same fields using Stored Procedure In SQL Server 2005

查看:77
本文介绍了使用存储过程在SQL Server 2005中将多个记录插入相同的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All

我想通过C#一次插入4个变量更新记录。如果我在C#表格中定义字段名称,如接收日期,接收时间,产品名称,产品数量。如果任何记录更新然后影响到CurValue并将PreValue存储为更新之前的Previous值。那么,我的问题是如果我一次更新4个以上的字段,那么只插入最后一个字段更新记录。我是如何解决这个问题的?如下所示我在SQL Server 2005中使用过程。



Hello All
I want to insert 4 variables update records at a time through C#. If I define Field Name like Receive Date,Receive time,Prod Name,Prod Qty in C# Form. If any record update then effect to CurValue and store PreValue as Previous value which was before update.So, My problem is if i update above 4 Fields at a time then only insert last field update record. How I resolve this problem? As below i am using Procedure in SQL Server 2005.

Insert Into ADT
(Hh,Slno,FieldName,CurValue,PreValue,Reason,FileNo,UpdateBy,UpdateDt,UpdateTm)
 values
(@Hh,@Slno,@FieldName,case when @CurValue='' then NULL else @CurValue end,
                      case when @PreValue='' then NULL else @PreValue end,
                      case when @Reason='' then NULL else @Reason end,
 @FileNo,@UpdateBy,@UpdateDt,@UpdateTm)

推荐答案

而不是 CASE .. WHEN ... END 语句,请使用 NULLIF [ ^ ]方法添加 NULL (如果是空字符串'')或任何其他值。



顺便说一句:您的SP不会更新任何内容。每次上面的查询都会添加新值。要更新记录,请使用更新 [ ^ ]声明。
Instead CASE.. WHEN ... END statement, use NULLIF[^] method to add NULL (in case of empty string '') or any other value.

By the way: your SP do not update anything. Every time above query adds new values. To update record, use UPDATE[^] statement.


这篇关于使用存储过程在SQL Server 2005中将多个记录插入相同的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆