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

我需要為每個字段重寫 case 語句嗎?

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

問題描述

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

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 中創建的,并根據需要為多列引用.

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

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

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.

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

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

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
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?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 日韩精品视频在线播放 | 国产成人免费视频 | 伊人网在线播放 | 久久精品视频一区 | 国产裸体永久免费视频网站 | 国产一区二区三区久久 | 天堂网亚洲 | 在线观看av不卡 | 亚洲天堂一区 | 免费视频a | 国产福利视频 | 青娱乐av | 天天干天天草 | 久久免费网 | www久久久久 | 久久国产精| 91久久久久久久久久久 | 精品久久久久久久久久久 | 成人一级视频 | 日本a级大片| 91免费高清视频 | 福利网站在线观看 | 欧美日韩成人在线观看 | 午夜精品久久久久久久久久蜜桃 | 91精品国产综合久久久久久 | 亚洲免费精品视频 | 久久久久成人网 | 欧美视频一二三区 | 香蕉一区二区 | 啪啪免费网站 | 黄色小视频在线播放 | 欧美一级二级三级 | 久久综合在线 | 日本一级一片免费视频 | 青青草网站 | 在线观看的av | 欧美成人小视频 | 韩日在线视频 | 欧美在线a | 精品第一页 | 日韩欧美在线播放 |