久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

我需要為每個(gè)字段重寫 case 語句嗎?

do i need to rewrite the case statement for every field?(我需要為每個(gè)字段重寫 case 語句嗎?)
本文介紹了我需要為每個(gè)字段重寫 case 語句嗎?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

兩列的 case 條件相同.在下面的語句中,我使用了兩次但對(duì)于不同的列,有沒有其他方法可以不重復(fù)兩次條件??

The case condition for two columns is same.in the below statement am using this twice but for different column, is there any other way for not repeating the condition twice ??

case [CPHIL_AWD_CD]
                     when ' ' then 'Not Applicable/ Not a Doctoral Student'
                     when 'X' then 'Not Applicable/ Not a Doctoral Student'
                     when 'N' then 'NO'
                     when 'Y' then 'YES'
                end as CPHIL_AWD_CD

              ,case [FINL_ORAL_REQ_CD] 
                     when ' ' then 'Not Applicable/ Not a Doctoral Student'
                     when 'X' then 'Not Applicable/ Not a Doctoral Student'
                     when 'N' then 'NO'
                     when 'Y' then 'YES'
                end as FINL_ORAL_REQ_CD

推薦答案

thepirat000 答案的變體:

A variation on thepirat000's answer:

-- Sample data.
declare @Samples as Table (
  Frisbee Int Identity Primary Key, Code1 Char(1), Code2 Char(2) );
insert into @Samples values ( 'Y', 'N' ), ( ' ', 'Y' ), ( 'N', 'X' );
select * from @Samples;

-- Handle the lookup.
with Lookup as (
  select * from ( values
    ( ' ', 'Not Applicable/ Not a Doctoral Student' ),
    ( 'X', 'Not Applicable/ Not a Doctoral Student' ),
    ( 'N', 'No' ),
    ( 'Y', 'Yes' ) ) as TableName( Code, Description ) )
select S.Code1, L1.Description, S.Code2, L2.Description
    from @Samples as S inner join
      Lookup as L1 on L1.Code = S.Code1 inner join
      Lookup as L2 on L2.Code = S.Code2;

查找表是在 CTE 中創(chuàng)建的,并根據(jù)需要為多列引用.

The lookup table is created within a CTE and referenced as needed for multiple columns.

更新:由于某些莫名其妙的原因,表變量現(xiàn)在擁有主鍵.如果有人能真正解釋它如何有利于性能,我很想聽聽.從執(zhí)行計(jì)劃上看不明顯.

Update: The table variable is now blessed with a primary key for some inexplicable reason. If someone can actually explain how it will benefit performance, I'd love to hear it. It isn't obvious from the execution plan.

這篇關(guān)于我需要為每個(gè)字段重寫 case 語句嗎?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對(duì)?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(hào)(問題和答案的組合))
主站蜘蛛池模板: 亚洲毛片在线观看 | 四虎影院免费在线播放 | 噜久寡妇噜噜久久寡妇 | 亚洲一二三区在线观看 | 久久99精品久久久久久 | av网站在线免费观看 | 精品日韩一区二区三区av动图 | 欧美一级毛片久久99精品蜜桃 | 欧美日韩亚洲国产综合 | 亚洲精品成人免费 | 婷婷激情综合 | 中文字幕一区二区三区精彩视频 | 亚洲一区二区三区在线 | 国产精品国产三级国产播12软件 | 国产精品久久久久久久久图文区 | 狠狠干天天干 | 日韩一区中文字幕 | 午夜精品久久久久久久久久久久久 | 国产网站在线免费观看 | jizz在线看片 | 亚洲成人一二区 | 激情av免费看| 国产精品久久久 | 精品国产鲁一鲁一区二区张丽 | 久久国内精品 | 成人午夜免费视频 | 国产www成人| 夜夜爽99久久国产综合精品女不卡 | 日日摸夜夜爽人人添av | 日韩一二三区 | 欧美午夜精品 | 国产91 在线播放 | 综合国产第二页 | 日日欧美 | 久久影院一区 | 99久久婷婷国产综合精品电影 | 综合色久| 日韩成人免费视频 | 91麻豆精品国产91久久久更新资源速度超快 | 国产一区中文字幕 | 国产精品久久久久永久免费观看 |