Visual Studio Cte 的 TableAdapter 问题

Visual Studio TableAdapter Issue With Cte

我有一个 query.It 可以在 MSSQL Management Studio 上正常工作 2008r2.Any error.I 将使用查询 report.So 我正在将 TableAdapter 添加到 Dataset.When我像这样添加查询抛出异常

WITH t1 AS 
(
    select  CONVERT(VARCHAR(24),tarihi, 103) tarihi,emp1.EmployeeCode,emp1.EmployeeID,emp1.EmployeeName
    from Personel.dbo.Dates d 
        cross join 
        (
            SELECT EmployeeCode,EmployeeID, EmployeeName 
            from TEmployee where EmployeeName <> '' AND  EmployeeName != 'MISAFIR'
        )   emp1 where d.tarihi between '2017-04-28' and '2017-05-05' 
),
t2 AS 
(
        SELECT 
        emp.EmployeeCode,
        CONVERT(VARCHAR(24), e.EventTime, 103) AS EventTime, 
        CONVERT(VARCHAR(24), MIN(e.EventTime), 108) AS GirisSaat, 
        CONVERT(VARCHAR(24), MAX(e.EventTime), 108) AS CikisSaat, 
        CONVERT(VARCHAR(5), MAX(e.EventTime) - MIN(e.EventTime), 108) AS total 
        FROM     
        TEvent AS e 
        LEFT OUTER JOIN TEmployee AS emp ON emp.EmployeeID = e.EmployeeID
        WHERE  (e.EventType <> 1) and EventTime between '2017-04-28' and '2017-05-05' 
        GROUP BY CONVERT(VARCHAR(24), e.EventTime, 103), e.EmployeeID, emp.EmployeeName, emp.EmployeeCode
)

 SELECT 
 t1.tarihi ,
 t1.EmployeeCode,
 t1.EmployeeName,
 ISNULL(t2.GirisSaat,'00:00:00') GirisSaat,
 ISNULL(t2.CikisSaat,'00:00:00') CikisSaat,


 ISNULL(ISNULL(t2.total,(SELECT '08:00' FROM Personel.dbo.izinli_listesi il
left join Personel.dbo.izin izn on izn.id = il.izin_id
 where 
 personel_id = t1.EmployeeID and 
 CONVERT(VARCHAR(24),t1.tarihi, 103) between CONVERT(VARCHAR(24),izin_bas_tar, 103) and CONVERT(VARCHAR(24),izin_bit_tar, 103))
  ),'00:00') total,

  isnull(CASE WHEN t2.total IS NULL 
    THEN 
        (SELECT izin_adi FROM Personel.dbo.izinli_listesi il
         left join Personel.dbo.izin izn on izn.id = il.izin_id 
          where  personel_id = t1.EmployeeID and 
          CONVERT(VARCHAR(24),t1.tarihi, 103) between CONVERT(VARCHAR(24),izin_bas_tar, 103) and CONVERT(VARCHAR(24),izin_bit_tar, 103))
    ELSE
         NULL 
    END,'')

   izindurumu  

 from t1 
  left join t2 on t2.EmployeeCode = t1.EmployeeCode and t2.EventTime=t1.tarihi
 order by t1.EmployeeCode, t1.tarihi

我认为这是关于 Cte.I checkced old questions.I 没有使用“*”。

错误:

the multi-part identifier "t2.total" could not be bound
the multi-part identifier "t1.EmployeeID" could not be bound
the multi-part identifier "t1.tarihi" could not be bound
and again
the multi-part identifier "t1.tarihi" could not be bound

我该如何解决?

我解决了我 problem.Didn 未在数据集设计器上添加查询 page.I 创建了一个 sql 存储过程然后使用数据集 designer.It 解决了我的问题。