本文介绍了如何在SQL Server 2005中同时将m更新为f和将f更新为m的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



假设我有一个表,其结构为

Hi,

Suppose I have a table structured as

name     |   gender
 anthony       m
 micheal       m
 jane          f
 kim           f






现在假设我想将m更改为f,同时将f更改为m
我是这样我想同时将m替换为f和f替换为m.我该怎么办?

在执行sql查询后,我应该获得的表结构应如下所示:






Now suppose I want to change m to f and at the same time f to m how can
I do so. I want to replace m to f and f to m simultaneously. How can i do so?

The table structure I should get after executing the sql query should be like this after

name     |   gender
 anthony       f
 micheal       f
 jane          m
 kim           m



请帮忙.



Please help.

推荐答案

<br />
<pre lang="sql"><br />
UPDATE [MyTable]<br />
SET GENDER = CASE<br />
                WHEN GENDER=''M'' THEN ''F''<br />
                WHEN GENDER=''F'' THEN ''M''<br />
                ELSE GENDER<br />
             END</pre><br />




这篇关于如何在SQL Server 2005中同时将m更新为f和将f更新为m的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 12:04