我有2個SQL查詢我嘗試使用linqer轉換但沒有結果。查詢是這樣的:在LINQ中轉換SQL查詢並選擇計數
select distinct a.DOCID,
(select dcrea from mstdocs where DOCID = a.docid and vtype = 'table') DOC_DATE,
(select dcrea from mstdocs where DOCID= a.docid and vtype = 'read' and VTAID = '2') Read_DATE
from mstdocs a, mstdocstats b
where a.docid = b.docid
and a.vtaid = '2'
and a.vtype = 'read'
and DATEPART(mm,a.DCREA) = '06'
and DATEPART(yyyy,a.DCREA) = '2016'
and a.docid in
(
select distinct a.docid
from mstdocs a, mstdocstats b
where a.docid = b.docid
and a.vtype = 'table'
and DATEPART(mm,a.DCREA) = '06'
and DATEPART(yyyy,a.DCREA) = '2016'
)
select distinct a.docid
from mstdocs a, mstdocstats b
where a.docid = b.docid
and (select count(*) from mstdocs docs where docs.DOCID = a.docid and docs.vtaid = '2') = 1
我有嘗試轉換第一個查詢分成兩個部分
風險價值=(從b在mstdocstats 在mstdocs上a.docid加入等於B。的docID 其中a.vtype.Equals( 「表」) & & a.DCREA.Month == '06' & & a.DCREA.Year == '2016' 選擇a.docid).Distinct()。ToList ();
變種B =(從步驟b中mstdocstats 加入在上a.docid mstdocs等於b.docid 其中a.Contains(a.docid) 選擇新的{ 文檔ID = a.docid, DOC_DATE = (從mstdocs其中a.docid == mstdoc.docid & & mstdoc.vtype == 「表」 mstdoc選擇
mstdoc.DCREA),
Read_DATE =(從mstdocs mstdoc其中a.docid == mstdoc.docid & & mstdoc.vtype ==「讀」& &
mstdoc.vtaid ==「2」select mstdoc.DCREA)})。ToList();
但變得錯誤,有人可以告訴我哪裏是錯誤嗎?
感謝任何答案...
是字段dcrea是日期時間,但我編譯該查詢和結果是標識符預期; 'in'是一個關鍵字,如果我想將該查詢存儲到列表中,我可以在distinct()後給tolist()嗎? –
絕對是的..你可以添加toList()在查詢 –
但我沒有結果,我不是爲什麼會變成錯誤:( –