谁帮我改改这句SQL!

sgp1201 2003-04-04 05:26:02
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 projectid in (select projectid from ProAccredit where userid='Su'))

当proAccredit中查询记录为空时,会出错,认帮我改一下好吗?
...全文
11 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sgp1201 2003-04-07
不是转换的问题,当userid有值是如='su'是对的,当userid值为空=''是才会出错!继续啊,
已经好几天了,不会要让我写两句SQL来实现吧!
回复
pengdali 2003-04-04
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'))
回复
j9988 2003-04-04
没数据时不会出错。

可能是:userid='Su' 出错了。
回复
sgp1201 2003-04-04
服务器: 消息 8114,级别 16,状态 5,行 7
将数据类型 varchar 转换为 numeric 时出错。
这个错误是最后一个条件:
[...and a.projectid in (select projectid from ProAccredit where userid='Su')]
当括号中查询值为空时,就会出这个错,也就是说,proaccredit中没数据时要处理一下
请继续关注,谢了!
回复
CSDNM 2003-04-04
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))
回复
pengdali 2003-04-04
不会呀!你用它会报什么错?
回复
ny64 2003-04-04
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')
回复
CrazyFor 2003-04-04
出什么错了,贴出来!
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2003-04-04 05:26
社区公告
暂无公告