现在的位置: 首页 > 综合 > 正文

SQL case

2013年04月08日 ⁄ 综合 ⁄ 共 368字 ⁄ 字号 评论关闭

SQL Server中的case的用法一:

Select top 100 State,JoinState, 
(    

        case 

        when State=1 and Joinstate=0     then 2 

        when State=1 and JoinState=1     then 1 

        else 0 

        end

    ) as usestate 

from UserInfo

 

用法二:

Select Name,Age,

(    

        case Sex

        when '男'     then  '先生'        

        when '女'     then  '小姐'

        end

    ) as Sex

from User

 

抱歉!评论已关闭.