谁帮我改改这句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中查询记录为空时,会出错,认帮我改一下好吗?
...全文
34 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
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
  • 打赏
  • 举报
回复
出什么错了,贴出来!

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧