发布时间:2011-08-29 13:10 来源:未知
之前我们介绍过:SQL Server 2008学习笔记之联合结果集union的使用,本文我们介绍一下SQL Server 2008学习笔记之去重和给新加字段赋值的相关知识,接下来就让我们一起来了解一下这部分内容吧。
增加两个字段:
alter TABLE T_Employee Add FSubCompany VARchar(20); ALTER TABLE T_Employee ADD FDepartment VARCHAR(20);
给新加的字段赋值
UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='Development' where FNumber='DEV001'; UPDATE T_Employee SET FSubCompany='ShenZhen',FDepartment='Development' where FNumber='DEV002'; UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='HumanResource' where FNumber='HR001'; UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='HumanResource' where FNumber='HR002'; UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='InfoTech' where FNumber='IT001'; UPDATE T_Employee SET FSubCompany='ShenZhen',FDepartment='InfoTech' where FNumber='IT002'; UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='Sales' where FNumber='SALES001'; UPDATE T_Employee SET FSubCompany='Beijing',FDepartment='Sales' where FNumber='SALES002'; UPDATE T_Employee SET FSubCompany='ShenZhen',FDepartment='Sales' where FNumber='SALES003';
查询并去重
select distinct FDepartment from T_Employee select distinct FDepartment,FSubCompany from T_Employee
关于SQL Server 2008学习笔记之去重和给新加字段赋值的相关知识就介绍到这里了,希望本次的介绍能够对您有所收获!