SELECT DATE, PASSWORK, STORED, PEACODE, AMP, COUNT(AMP) AS Amp, PS, PS_UNINSTALL AS PSUNINSTALL
FROM ZDMR101
WHERE (DATE_INSTALL IS NOT NULL) AND (PS_UNINSTALL <> 'ถ.เลิกใช้ไฟ') AND (PS_UNINSTALL <> 'ถ.ค้างชำระค่าไฟ') AND (PS_UNINSTALL <> 'ป.ลดขนาด') AND
(PS_UNINSTALL <> 'ป.เพิ่มขนาด')
GROUP BY PASSWORK, STORED, PEACODE, AMP, PS, PS_UNINSTALL, DATE
HAVING (PASSWORK = @Passwork)
อยากได้ query LINQ ตามนี้ ...
ผู้รู้ช่วยหน่อยน้าค้าบบ ..
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), LINQ, C#
ลองดูพวก LinqPad ครับ ใช้สำหรับแปลง SQL to Linq ครับ
Date :
2014-03-17 06:26:31
By :
mr.win
No. 2
Guest
Code (SQL)
SELECT DATE, PASSWORK, STORED, PEACODE, AMP, COUNT(AMP) AS Amp, PS, PS_UNINSTALL AS PSUNINSTALL
FROM ZDMR101
WHERE (DATE_INSTALL IS NOT NULL) AND NOT PS_UNINSTALL IN ('ถ.เลิกใช้ไฟ', 'ถ.ค้างชำระค่าไฟ', 'ป.ลดขนาด', 'ป.เพิ่มขนาด')
GROUP BY PASSWORK, STORED, PEACODE, AMP, PS, PS_UNINSTALL, DATE
HAVING (PASSWORK = @Passwork)
Code (C#)
var query = (from z in dbcontext.ZDMR101
where z.DATE_INSTALL != null && !z.PS_UNINSTALL.Contains("ถ.เลิกใช้ไฟ", "ถ.ค้างชำระค่าไฟ", "ป.ลดขนาด", "ป.เพิ่มขนาด")
group by z.PASSWORK, z.STORED, z.PEACODE, z.AMP, z.PS, z.PS_UNINSTALL, z.DATE into g
select new {
DATE = g.Key.DATE,
PASSWORK = g.Key.PASSWORK,
STORED = g.Key.STORED,
PEACODE = g.Key.PEACODE,
AMP = g.Key.AMP,
CountAMP = g.Count(z.AMP),
PS = g.Key.PS,
PSUNINSTALL = g.Key.PS_UNINSTALL
}).Where(z => z.PASSWORK == @Passwork);