我有以下 SQL 语句:
CASE
WHEN wt.pmtlr_oi IS NULL OR (SELECT COUNT(*) FROM mc.SCHEDENTRY WITH (NOLOCK) WHERE wt_oi = wt.wtskoi AND shedref_oi NOT IN (SELECT shdoi FROM mc.SCHDULE WITH (NOLOCK) WHERE aenm LIKE '%Breakin%')) = 0 AND wt.pmtlr_oi IS NULL
THEN 'Break-In'
ELSE 'Planned'
END AS schedule
我已经翻译成:
Schedule = wt.pmtlr_oi == null || (from sch in SCHEDENTRies where wt_oi == wt.wtskoi && shedref_oi !(from sc in SCHDULEs
where sc.Aenm.Contains("Breakin") select sc.Shdoi)).Count() == 0 && wt.pmtlr_oi == null ? "Break-In" : "Planned"}
下面是它在 select 语句中的样子:
select new {Schedule = wt.pmtlr_oi == null || (from sch in SCHEDENTRies where wt_oi == wt.wtskoi && shedref_oi !(from sc in SCHDULEs
where sc.Aenm.Contains("Breakin") select sc.Shdoi)).Count() == 0 && wt.pmtlr_oi == null ? "Break-In" : "Planned"});
但是,当我尝试运行它时,会出现一些我不知道如何解决的问题。第一个是编译器似乎不喜欢此处的 NOT IN:
&& shedref_oi !(from sc in SCHDULEs
我收到“查询正文必须以 select 子句或 group 子句结尾”错误。
编译器也不喜欢这样:
select sc.Shdoi)).Count() == 0
在外括号中,我收到“语法错误”,“预期”错误,在期间我收到“预期声明”错误消息。
我将不胜感激解决此问题的一些帮助。
编辑:
好的,在评论之后,我将 LINQ 语句更正为如下所示:
select new {Schedule = wt.pmtlr_oi == null || (from sch in SCHEDENTRies where wt_oi == wt.wtskoi && !(from sc in SCHDULEs
where sc.Aenm.Contains("Breakin") select sc.Shdoi).Contains(shedref_oi)).Count() == 0 && wt.pmtlr_oi == null ? "Break-In" : "Planned"});
并且编译器喜欢它。但是,它仍然不喜欢 .Count()。我收到“预期声明”错误。我在为 sql SELECT COUNT(*) 使用 .Count() 时不正确吗?