select a.unitid,a.Projectid,a.ProjectName,a.SalePlan,
a.estimate,a.StartTime,a.EndTime,a.sales,a.InputTime,
a.ForecastMoney,b.Name 
from Project a,Archives b 
where a.sales=b.userid 
and (a.sales='Su' )
Union
select a.unitid,a.Projectid,a.ProjectName,a.SalePlan,
a.estimate,a.StartTime,a.EndTime,a.sales,a.InputTime,
a.ForecastMoney,b.Name 
from Project a,Archives b 
where a.sales=b.userid 
and a.projectid in (select projectid from ProAccredit where userid='Su')

解决方案 »

  1.   

    select a.unitid,a.Projectid,a.ProjectName,a.SalePlan,
    a.estimate,a.StartTime,a.EndTime,a.sales,a.InputTime,
    a.ForecastMoney,b.Name 
    from Project a,Archives b 
    where a.sales=b.userid 
    and (a.sales='Su' or exists (select 1 from ProAccredit where userid='Su' and projectid=a.projectid))
    或者(不知道你的projectid字段是那个表的):
    and (a.sales='Su' or exists (select 1 from ProAccredit where userid='Su' and projectid=b.projectid))
      

  2.   

    服务器: 消息 8114,级别 16,状态 5,行 7
    将数据类型 varchar 转换为 numeric 时出错。
    这个错误是最后一个条件:
    [...and a.projectid in (select projectid from ProAccredit where userid='Su')]
    当括号中查询值为空时,就会出这个错,也就是说,proaccredit中没数据时要处理一下
    请继续关注,谢了!
      

  3.   

    没数据时不会出错。可能是:userid='Su' 出错了。
      

  4.   

    select a.unitid,a.Projectid,a.ProjectName,a.SalePlan,
    a.estimate,a.StartTime,a.EndTime,a.sales,a.InputTime,
    a.ForecastMoney,b.Name 
    from Project a,Archives b 
    where a.sales=b.userid 
    and (cast(a.sales as varchar(100))='Su' or cast(projectid as varchar(100)) in (select projectid from ProAccredit where userid='Su'))
      

  5.   

    不是转换的问题,当userid有值是如='su'是对的,当userid值为空=''是才会出错!继续啊,
    已经好几天了,不会要让我写两句SQL来实现吧!