求条SQL语句,想从A库一个表(表名:ABCD)中查某个时段(2012-01-10至2012-02-10)的数据,但要符合B库表(DBCA)中的一个字段(字段名:BZ)要求,这个字段不是两表共同的字段,两个表中有一个共同的字段(字段:JZH)。

解决方案 »

  1.   

    BZ字段要求不明确,暂时用BZ代替true,表示你的要求,具体你再修改
    select *
    from ABCD
      inner join DBCA on ABCD.JZH=DBCA.JZH
    where time between '2012-1-10' and '2012-2-10'
      and BZ
      

  2.   

    我用你那个,增加了一下,好像不行呀?
    select XM as 姓名,RQ as 日期,YSK as 金额,MZJLID as 机制号,SFZF as 是否作废,''as 发票号,'' as 备注 from dthhis.dbo.T_M_MZ0101 inner join FPLY on dthhis.dbo.T_M_MZ0101.MZJLID=FPGL.dbo.FPLY.MZJLID where SFZGID='44'AND RQ between '2012-1-10' and '2012-2-10'
     AND SFYYBZ ='' order by MZJLID ASC
     
    查询分析中提示如下:
    服务器: 消息 208,级别 16,状态 1,行 1
    对象名 'FPLY' 无效。
      

  3.   


    这样可以
    select *,''as 发票号,'' as 备注 from dthhis.dbo.T_M_MZ0101 inner join FPGL.dbo.FPLY on dthhis.dbo.T_M_MZ0101.MZJLID=FPGL.dbo.FPLY.MZJLID where SFZGID='44'AND RQ between '2012-1-10' and '2012-2-10'
     AND SFYYBZ ='' order by dthhis.dbo.T_M_MZ0101.MZJLID ASC
      

  4.   

    dthhis.dbo.T_M_MZ0101 inner join FPLY on dthhis.dbo.T_M_MZ0101.MZJLID=FPGL.dbo.FPLY.MZJLID where SFZGI
    改成FPGL.dbo.FPLY
      

  5.   

    select dthhis.dbo.T_M_MZ0101.XM as 姓名,dthhis.dbo.T_M_MZ0101.RQ as 日期,dthhis.dbo.T_M_MZ0101.YSK as 金额,dthhis.dbo.T_M_MZ0101.MZJLID as 机制号,dthhis.dbo.T_M_MZ0101.SFZF as 是否作废,''as 发票号,'' as 备注 from dthhis.dbo.T_M_MZ0101 inner join FPGL.dbo.FPLY on dthhis.dbo.T_M_MZ0101.MZJLID=FPGL.dbo.FPLY.MZJLID where SFZGID='44'AND RQ between '2012-1-10' and '2012-2-10'
     AND SFYYBZ ='' order by dthhis.dbo.T_M_MZ0101.MZJLID ASC
      

  6.   

    SELECT BZ 
    FROM A.dbo.DCBA A 
    WHERE EXISTS(SELECT 1 FROM ABCD WHERE JZH=A.JZH AND RQ >='2012-01-10' AND RQ<='2012-02-10')
      

  7.   


    select *
    from ABCD
      inner join DBCA on ABCD.JZH=DBCA.JZH
    where time between '2012-1-10' and '2012-2-10'
      

  8.   


    SELECT * FROM A.ABCD 
    WHERE 时间 between '2012-01-01' and '2012-02-10'
    AND EXISTS(
    SELECT 1 FROM B.DCBA 
    WHERE A.ABCD.JZH=B.DCBA.JZH 
    AND BZ...
    )