带CASE的SQL存储过程

时间:2013-09-18 10:48:42

标签: sql sql-server

你好,我的存储过程有一个quation,我在这里使用2个案例,第一个案例它显示我正确的值和它的确定,第二个显示我只在字段TirType中的Null值,我不明白什么是问题

CREATE VIEW dbo.YUITY
    SELECT     CAST(dbo.SC5116.CODE AS int) AS код, dbo.SC5116.DESCR AS Наименование,    
     CAST(dbo.SC3420.CODE AS int) AS TIR, dbo.SC3420.SP4947 AS Date, 
                  CASE WHEN SC3420.SP4949 <> '     0   ' THEN 'ПовышСтрах' ELSE 'ОснСтрах' END AS VID, 
                  CASE WHEN dbo.SC3420.SP9214 = '714' THEN '4v' END AS TirType
      FROM         dbo.SC3420 INNER JOIN
                  dbo.SC5116 ON dbo.SC3420.SP3422 = dbo.SC5116.ID
       WHERE     (dbo.SC3420.SP4947 <> '01.01.1753')

1 个答案:

答案 0 :(得分:1)

END之后不要忘记CASE。如果未指定ELSE且值不是'714',它将返回NULL。

CREATE VIEW dbo.YUITY
AS
    SELECT     CAST(dbo.SC5116.CODE AS int) AS код, dbo.SC5116.DESCR AS Наименование,    
     CAST(dbo.SC3420.CODE AS int) AS TIR, dbo.SC3420.SP4947 AS Date, 
                  CASE WHEN SC3420.SP4949 <> '     0   ' THEN 'ПовышСтрах' ELSE 'ОснСтрах' END AS VID, 
                  CASE WHEN dbo.SC3420.SP9214 = '714' THEN '4v' ELSE '' END AS TirType
      FROM         dbo.SC3420 INNER JOIN
                  dbo.SC5116 ON dbo.SC3420.SP3422 = dbo.SC5116.ID
       WHERE     (dbo.SC3420.SP4947 <> '01.01.1753')