帮助调试sql查询:我在哪里有额外的(或)?

时间:2010-10-06 15:31:22

标签: sql sql-server

我收到2个错误:
   1)关键字union zh_cn附近的语法不正确    2)')'

附近的语法不正确

以下是查询:

select count(*) as numUsers, count(r.cabGroupId) as numCompanies from
            (select r.newUserId, r.groupId
            from reportaccesslogs r full outer myTable d
            on r.num = d.num
            where (r.reportId = 1) and (r.groupId not in (666, 999))
            and ((r.num1 = @num1)) or (d.num1 = @num1))

            union

            select userId, groupId 
            from detailsLog
            where (num1 = coalesce(@num1, num1)) and (num2= @num2) and (num3= coalesce(@num3, num3)) 
            and (groupId not in (666, 999))) tmp

2 个答案:

答案 0 :(得分:1)

select count(*) as numUsers, count(r.cabGroupId) as numCompanies 
from
            (select r.newUserId, r.groupId
            from reportaccesslogs r full outer myTable d
            on r.num = d.num
            where (r.reportId = 1) and (r.groupId not in (666, 999)
            and ((r.num1 = @num1) or (d.num1 = @num1)))

            union

            select userId, groupId 
            from detailsLog
            where (num1 = coalesce(@num1, num1)
            and (groupId not in (666, 999)))) tmp

看看是否有效。

答案 1 :(得分:0)

确定你在tmp

旁边的最后一行有额外的')'