WHERE子句出错

时间:2015-02-24 20:11:56

标签: sql datetime where

我创建了一个包含2列的视图,这里是我的观点代码:

SELECT
  CONVERT(DATETIME, a.ValorF) AS FechaCumplimiento
  ,CONVERT(NVARCHAR(50), a.FlowID) AS FlowID
   FROM (SELECT fd.ValorF
    ,fd.FlowID
    FROM Qflow.dbo.FlowData fd 
    INNER JOIN Qflow.dbo.Flows f 
        ON fd.FlowID = f.FlowID
    WHERE ValorF IS NOT NULL
    AND f.TemplateID = 1211 AND fd.DataID = 8) a
  UNION ALL
  SELECT
  CAST(
  REPLACE
  (REPLACE
  (REPLACE
  (REPLACE
  (REPLACE
  (f.Value,'<Vs>',''),'<V>',''),'</V>',''),'</Vs>',''),'Z','')AS DATETIME) AS FechaCumplimiento
   , f.FlowID
   FROM (SELECT 
   fs.Value
  ,CONVERT(NVARCHAR(50), fs.FlowID) AS FlowID 
  FROM [Qflow3].[dbo].[FlowData] fs
    INNER JOIN [Qflow3].[dbo].[TemplateData] t
        ON fs.TemplateDataID = t.TemplateDataID
  WHERE fs.FlowID IN (SELECT fi.FlowId
                      FROM Qflow3.dbo.Flow fi
                      WHERE TemplateID = '2EA13351-7838-4BAF- A6CD-B768688F4C47') 
AND t.Name = '_FECHACUMPLIMIENTO'
AND t.Description = 'Recomendacion') f

现在我试图这样做:

SELECT 
YEAR(f.FechaCumplimiento) AS Anio
FROM [dbo].[vi_CAR_FecCumplimiento] f
WHERE YEAR(f.FechaCumplimiento) = 2010
ORDER BY f.FechaCumplimiento ASC

但我收到此错误:从字符串转换日期和/或时间时转换失败。

我在我的观点和查询中尝试了很多更改,但似乎无法正常工作。

0 个答案:

没有答案