How do I swap column values in sql server 2008?

后端 未结 8 536
春和景丽
春和景丽 2020-12-08 09:40

I have a table called Employee

 Eno     ename     AttributeValue      AttributeName  
 1       aa           a123             abc
 2       bbb          b123           


        
相关标签:
8条回答
  • 2020-12-08 10:09

    This is really good example

    SELECT * from employees;
    Go
    
    DECLARE @temp as varchar(20)
    update employees
    set    @temp = fname,
           fname = lname,
           lname = @temp
    WHERE  deptno = 10;
    GO
    
    SELECT * from employees;
    

    Result

    0 讨论(0)
  • 2020-12-08 10:13

    update Employee set AttributeValue = AttributeName, AttributeName = AttributeValue

    0 讨论(0)
提交回复
热议问题