码迷,mamicode.com
首页 > 其他好文 > 详细

case then 的用法 貌似case then不支持别名

时间:2014-07-22 22:45:14      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:des   io   cti   re   c   ar   

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROC [dbo].[usp_SRV_GetALLRelativeProject]
@ServiceOrderID VARCHAR(50)
AS
/*
PAGE: 通过服务单ID 获取该服务单关联的单子信息    
Action: 服务单处理页面

CreatedBy: XXX
CreatedDate: 20101021
ModifiedHistory:

Test Scripts:

EXEC usp_SRV_GetALLRelativeProject ‘SRV000000014‘

*/ 
BEGIN
SELECT d.[Type],
d.TypeID,
d.[Desc],
d.VariationOrderID,
CASE 
WHEN d.WorkOrderStatus IS NULL THEN d.SrvOrderStatus
ELSE d.WorkOrderStatus
END AS Status,
CASE 
WHEN d.WorkOrderHName IS NULL THEN d.SrvOrderHName
ELSE d.WorkOrderHName
END AS HName
FROM (
   SELECT r.[Type],
   r.TypeID,
   r.VariationOrderID,
   r.[Desc],
   a.DictName AS SrvOrderStatus,
   hand.HName AS SrvOrderHName,
   CASE wo.Status
   WHEN 1 THEN ‘处理中‘
   WHEN 2 THEN ‘完成‘
   END AS WorkOrderStatus,
   wo.HandlerName AS WorkOrderHName
   FROM dbo.tbl_VariationOrderRelativeProject r
   INNER JOIN tbl_ServiceOrder s
   ON r.VariationOrderID = @ServiceOrderID
   AND s.ServiceOrderID = @ServiceOrderID
   LEFT JOIN (
    SELECT * FROM dbo.tbl_Dictionary
    WHERE DictType = ‘ServiceOrderStatus‘
   ) a
   ON s.StatusCode = a.DictCode
   LEFT JOIN tbl_ServiceHandlerInfo hand
   ON r.VariationOrderID = hand.ServiceOrderID
   LEFT JOIN dbo.tbl_ServiceWorkOrder wo
   ON r.TypeID = wo.ServiceWorkOrderID
) d

END

case then 的用法 貌似case then不支持别名,布布扣,bubuko.com

case then 的用法 貌似case then不支持别名

标签:des   io   cti   re   c   ar   

原文地址:http://www.cnblogs.com/niaowo/p/3859849.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!