首页 > 数据库技术 > 详细

T-SQL Case 嵌套 Case

时间:2015-11-24 11:09:46      阅读:297      评论:0      收藏:0      [点我收藏+]
SELECT JournalEntryId,
       JournalEntryNo,
       CapitalChain,
       DataSource,
       EntrySummary,
       AccountSubject,
       CASE AccountSubject
         WHEN ‘应付账款‘ THEN ‘卡门网供应商‘
         WHEN ‘应收账款‘ THEN ‘卡门网客户‘
         WHEN ‘预收账款‘ THEN ( CASE
                              WHEN JournalEntryNo LIKE ‘API%‘ THEN ‘API预收客户款‘
                              WHEN JournalEntryNo = ‘CSC004‘ THEN ‘CSC预收客户款‘
                              WHEN JournalEntryNo = ‘CSC005‘ THEN ‘卡门网预收客户款‘
                              WHEN JournalEntryNo LIKE ‘KYS%‘ THEN ‘卡吧零预收客户款‘
                              WHEN JournalEntryNo LIKE ‘ZH%‘ THEN ‘卡门网预收客户款‘
                              WHEN JournalEntryNo LIKE ‘ZJC%‘ THEN ‘卡门网预收客户款‘
                            END )
         ELSE ‘‘
       END AS AccountSubjectDetail,
       DebitAmount*-1 AS DebitAmount,
       CreditAmount*-1 AS CreditAmount,
       OffsetCategory,
       CustomerSiteType,
       BusinessTypeId,
       JournalEntryTime,
       InputTime
FROM   dbo.JournalEntry
WHERE  JournalEntryTime >= ‘2015-08-23 00:00:00.000‘
       AND JournalEntryTime <= ‘2015-08-23 23:59:59.999‘
       AND AccountSubject IN (‘应收账款‘, ‘应付账款‘, ‘预收账款‘)
       AND CustomerSiteType = ‘外部站点‘

T-SQL Case 嵌套 Case

原文:http://blog.csdn.net/lee576/article/details/50009135

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!