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

如何在同一查詢中將一個數據字段用于另一個

How to use one data field into another case expression in the same query(如何在同一查詢中將一個數據字段用于另一個 case 表達式)
本文介紹了如何在同一查詢中將一個數據字段用于另一個 case 表達式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想在 CASE 表達式的第二部分使用 SNumber 但不知道如何使用它?

I want to use SNumber in the second part of CASE expression but not sure how to use it?

    select    
        PE.EDateTime,
        (case when(PE.EDateTime is not NULL and cast(PE.EDateTime as time) < '12:30') then cast(format(PE.EDateTime,'yyyyMMddhhmm') as varchar(50))+'AM'
             when (PE.ADate is not NULL and cast(PE.ADate as time) < '12:30') then cast(format(PE.ADate,'yyyyMMddhhmm') as varchar(50))+'AM'
             when (PE.EDateTime is not NULL and cast(PE.EDateTime as time) >= '12:30') THEN  cast(format(PE.EDateTime,'yyyyMMddhhmm') as varchar(50))+'PM'
             when  (PE.ADate is not NULL and cast(PE.ADate as time) > '12:30') then cast(format(PE.ADate,'yyyyMMddhhmm') as varchar(50))+'PM'
             else null 
            end) as SNumber,
   
     case 
   when (SNumber like'%AM') then 'AM'
   when SNumber like '%PM') then 'PM'
   else null 
end as [Session],
        Comments   
    from (
        select       
            PE1.RId,
            PE1.ADate,
            PE1.EDateTime
        from (
            select
                RegEId, 
                ADate,
                EDateTime,
                Comments
            from PatEnr
            where PreNumber is not null               
            ) as PE1
        left join Pat PEA 
            on PE1.RegEId = PEA.RegEId   
        left join PBooking PB 
            on PB.RegEId = PE1.RegEId
        ) as PE

我想在下面的同一查詢中使用 SNumber ,但我無法使用它,因為這都屬于一個查詢.有沒有辦法在下面的 CASE 中使用上述內容?我想使用如下所示的內容.

I want to use SNumber here below in the same query but I am not able to use this as this all belongs to one query. Is there any way to use the above in below CASE? I want to use something like below.

case 
   when (SNumber like'%AM') then 'AM'
   when (SNumber like '%%PM') then 'PM'
   else null 
end as Session,

推薦答案

使用交叉應用來執行您可以重復使用的計算.

Use cross apply to perform your calculation which you can then reuse.

select
    SNumber
    , case when SNumber like '%AM%' then 'AM'
    when SNumber like  '%PM%' then 'PM'
    else null end as [Session]
from MyTable PE
cross apply (
values (
    case when(PE.EDateTime is not NULL and cast(PE.EDateTime as time) < '12:30') then cast(format(PE.EDateTime,'yyyyMMddhhmm') as varchar(50))+'AM'
    when (PE.ADate is not NULL and cast(PE.ADate as time) < '12:30') then cast(format(PE.ADate,'yyyyMMddhhmm') as varchar(50))+'AM'
    when (PE.EDateTime is not NULL and cast(PE.EDateTime as time) >= '12:30') THEN  cast(format(PE.EDateTime,'yyyyMMddhhmm') as varchar(50))+'PM'
    when (PE.ADate is not NULL and cast(PE.ADate as time) > '12:30') then cast(format(PE.ADate,'yyyyMMddhhmm') as varchar(50))+'PM'
    else null 
    end
)) x (SNumber)

注意:contains 在該上下文中不起作用 - 它是全文搜索的 where 子句謂詞,因此我已替換為 喜歡.

Note: contains doesn't work in that context - its a where clause predicate for full-text search, so I've replaced with like.

這篇關于如何在同一查詢中將一個數據字段用于另一個 case 表達式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 一二区视频| 亚洲国产精品99久久久久久久久 | 丝袜一区二区三区 | 国产高清在线视频 | 国产精品久久久久久久久久久久久久 | 免费观看一级特黄欧美大片 | 一级做a爰片性色毛片16 | 成人深夜福利在线观看 | 成人在线视频免费播放 | 91在线观看 | 亚洲五码在线 | 精品一级毛片 | 婷婷在线视频 | 日韩中文一区二区三区 | 日韩在线一区二区三区 | 精品动漫一区 | 麻豆久久久9性大片 | 粉嫩粉嫩芽的虎白女18在线视频 | 国产综合精品一区二区三区 | 91豆花视频 | 国产精品毛片一区二区三区 | 亚洲成av人片在线观看无码 | 久久国产一区 | 国产精品有限公司 | 亚洲国产成人精品久久 | 美女视频久久 | 免费av电影网站 | 久久久视频在线 | 成人免费视频在线观看 | 国产91成人 | 国产精品免费一区二区三区 | 亚洲精品一区二区三区 | 亚洲午夜精品一区二区三区 | 久久亚洲一区二区 | 成人一区二区三区视频 | 一级欧美一级日韩片 | 色香婷婷 | 99精品福利视频 | 成人亚洲片 | 精品久久久久久亚洲精品 | 国产丝袜人妖cd露出 |