1

incorrect syntax near as运行时接收inner join。需要确定为什么和不能。请指出哪里出错了:

相关SQL代码

from 

(   
    (
        (dbo.task inner join dbo.projwbs on dbo.task.proj_id=dbo.projwbs.wbs_id) as tmptb1
    inner join
        (dbo.task inner join dbo.project on dbo.task.proj_id=dbo.project.proj_id) as tmptb2
        on dbo.tmptb1.proj_id=dbo.tmptb2.proj_id as dbo.tmptb3
    )
    inner join
(
        (dbo.task inner join dbo.rsrc on dbo.task.rsrc_id=dbo.rsrs.rsrc_id) as tmptb4)
        on tmptb3.proj_id=tmptb4.proj_id
    )
4

2 回答 2

3

您的代码看起来有太多的括号,但很难准确地说出您在做什么。所以我会改变它以使用类似的东西:

select *
from 
(
    select *
    from
    (   
        select *
        FROM dbo.task 
        inner join dbo.projwbs 
            on dbo.task.proj_id=dbo.projwbs.wbs_id
    ) as tmptb1
    inner join
    (
        select *
        from dbo.task 
        inner join dbo.project 
            on dbo.task.proj_id=dbo.project.proj_id
    ) as tmptb2
        on tmptb1.proj_id=tmptb2.proj_id
) as tmptb3
inner join
(
    select *
    from dbo.task 
    inner join dbo.rsrc 
        on dbo.task.rsrc_id=dbo.rsrs.rsrc_id
) as tmptb4
    on tmptb3.proj_id=tmptb4.proj_id

将 替换为SELECT *每个表中所需的列。

我不确定您为什么要执行所有这些子查询来获取数据,您应该可以使用:

select *
from dbo.task t
inner join dbo.projwbs w
  on t.proj_id=w.wbs_id
inner join dbo.project p
  on t.proj_id=p.proj_id
inner join dbo.rsrc r
  on t.rsrc_id = r.rsrc_id
于 2013-02-04T20:07:59.710 回答
3

我可能遗漏了一些东西......但由于这些都是inner joins,我不确定这些块给你的简化版本也不会做:

from 
    dbo.task t
    inner join dbo.projwbs pw on t.proj_id=pw.wbs_id 
    inner join dbo.project p on t.proj_id=p.proj_id
    inner join dbo.rsrc r on t.rsrc_id=r.rsrc_id
于 2013-02-04T20:10:34.410 回答