在一列在同一表中的另一列存储旧数据并更新新数据 [英] Store old data in one column and update new data in another column within same table

查看:352
本文介绍了在一列在同一表中的另一列存储旧数据并更新新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是一个专业的程序员,但谁需要帮助的爱好者。这里是我的挑战:

I'm not a professional programmer but an enthusiast who needs help. Here is my challenge:

我有一个完整的为我们的员工数据表。

I have a table full of data for our employees.

目前,我们的任何员工可以到更新的网页上我们的网站,并输入自己的姓氏在 previous 一个显示在一个文本框,然后点击提交,他的姓氏将在数据库中更新。然而,我的上司要保持员工的 previous 姓氏在同一个表作为姓。她的想法是,当在他的最后在文本框中名雇员类型,它会触发数据库来存储自己的 previous 姓氏在一个名为别名列姓氏列,然后在更新他的姓氏。我如何与继续?

Currently, any of our employees can go to the "Update" web page on our web site and type in his new last name over the previous one that is displayed in a textbox and click submit, his last name will be updated in the database. However, my supervisor wants to keep the employees' previous last name in the same table as the new last name. Her idea is when an employee types in his new last name in the textbox, it will trigger the database to store his previous last name in a column called "Alias" and then update his new last name in the "LastName" column. How do I proceed with that?

下面是表的结构:

PeopleID (int)  
JobIDNum (int)  
EmployeeIDNum (varchar(25))  
Email (varchar(100))  
Password (varchar(50))  
LastName (varchar(50))  
FirstName (varchar(25))  
Deleted (char(1))  
Alias (varchar(50))  

我AP preciate任何协助和/或建议,我可以得到的。

I appreciate any assistance and/or advice I can get.

推荐答案

推荐一个存储过程,你可以从ASP调用。

Suggest a stored procedure that you can call from ASP.

 CREATE PROC UpdateEmp
    @EmpID  int,
    @LastName varchar(50),
    --all the others properties you need to update this person
 AS
 BEGIN

     UPDATE Employee
     SET Alias = LastName,
         LastName = @LastName,
         --all the other properties you want updated.
     WHERE PeopleID = @EmpID;

 END

调用此存储过程在ASP code是这样的:

Call this stored proc in your ASP code like this:

Dim cmd
Dim ln
Dim retCount    
Dim conn
Set conn= Server.CreateObject("ADODB.Connection")       
Set cmd = Server.CreateObject("ADODB.Command")      
conn.Open "some connection string"
With cmd
    .ActiveConnection = conn
    .Commandtext = "UpdateEmp"
    .CommandType = adCmdStoredProc
    .Parameters.Append .CreateParameter("@EmpID", adInteger, adParamInput, 10)
    .Parameters("@EmpID") = 22 'some Employee you get from your code
    .Parameters.Append .CreateParameter("@LastName", adVarChar, adParamInput, 50)
    .Parameters("@LastName") = "MyLastName" 'some Employee you get from your code
    .Execute ln, , adExecuteNoRecords
End With        
Set cmd = Nothing

这篇关于在一列在同一表中的另一列存储旧数据并更新新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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