2016-08-16 4 views
0

私は2つのSQLクエリを持っています。私はlinqerを使用して変換しようとしましたが、結果はありません。このようなクエリ:LINQとSelect Countで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 

私は最初のクエリはmstdocstats にBからの二つの部分

  • するvar A =(に分離変換しようとしているがa.docid上mstdocsに参加Bに等しいです。 DOCID a.vtype.Equals( "表") & & a.DCREA.Month == '06' & & a.DCREA.Year == '2016' a.docid).Distinct()を選択 。ToListメソッド();

  • するvar B =(mstdocstatsに がa.docidにmstdocsに参加Bはb.docid等しいからa.Contains(a.docid)は{新しい選択 DOCID = a.docid、 DOC_DATE =
    Read_DATE =(mstdocからmstdocsでa.docid == mstdoc.docid、(a.docidは==
    mstdoc.DCREAを選択& & mstdoc.vtype == "テーブル" をmstdoc.docid mstdocsでmstdocから) & & mstdoc.vtype == "read" & &
    mstdoc.vtaid == "2" mstdoc.DCREAを選択)})。ToList();

でもエラーになりますが、間違いがどこにあるか教えてください。すべての答えを

おかげで...

答えて

0

は、私が最初のクエリは、当初2016年6月日付間隔に落ちるのサブセットを取得し、このことから「の読み込みサブセットを取得します。.. DCREADatetimeであると仮定しました" ...

var qry_1 = (from a in (
       from a in mstdocs 
       join b in mstdocstats on a.docid equals b.docid 
       where a.DCREA.Month == 6 && a.DCREA.Year == 2016 
       select a 
      )join b in mstdocstats on a.docid equals b.docid 
      where a.vtaid == "2" && a.vtype == "read" 
      select new { 
         DOCID = a.Name, 
         Read_DATE = a.DCREA, 
         DOC_DATE = (from mstdoc in mstdocs where a.docid == mstdoc.docid && mstdoc.vtype == "table" select mstdoc.DCREA) 
        } 
      ).Distinct().ToList(); 




var qry_2 = (from a in 
      (from a in mstdocs 
       where a.vtaid == "2" 
       group a by a.docid into GroupMstdocs 
       where GroupMstdocs.Count() == 1 
       select new { docid = GroupMstdocs.Key } 
      ) join b in mstdocstats on a.docid equals b.docid 
       select a.docid 
      ).Distinct().ToList(); 
+0

はいフィールドdcreaはdatetimeですが、私はそのクエリをコンパイルし、結果は識別子が期待されています。 'in'はキーワードです。リストにそのクエリを格納したい場合は、distinct()の後にtolist()を付けることができますか? –

+0

絶対にそうです..質問に –

+0

のtoList()を追加することはできますが、結果はありません。理由はありません:( –

関連する問題