日期:2014-05-18  浏览次数:20565 次

sql语句查错
【SQL语句:】
select top 20 _SalesOrder.[salesOrderId] as _column1, _SalesOrder.[invoiceState] as _column2, _PickListMap.[displayText] as _column3, _SalesOrder.[status] as _column4, _PickListMap_1.[displayText] as _column5, _SalesOrder.[accountId] as _column6, _Account.[accountName] as _column7, _SalesOrder.[topic] as _column8, _SalesOrder.[totalAmount] as _column9, _SalesOrder.[contactId] as _column10, _Contact.[contactName] as _column11, _Contact.[accountId] as _column12, _Account_1.[accountName] as _column13 from [SalesOrder] as _SalesOrder left join [Account] as _Account on _Account.[accountId] = _SalesOrder.[accountId] left join ([Contact] as _Contact left join [Account] as _Account_1 on _Account_1.[accountId] = _Contact.[accountId]) on _Contact.[contactId] = _SalesOrder.[contactId] left join [DictMap] as _PickListMap_1 on _PickListMap_1.[objectTypeCode] = 16 and _PickListMap_1.[fieldName] = 'status' and _PickListMap_1.[fieldValue] = _SalesOrder.status left join [DictMap] as _PickListMap on _PickListMap.[objectTypeCode] = 16 and _PickListMap.[fieldName] = 'invoiceState' and _PickListMap.[fieldValue] = _SalesOrder.invoiceState where ( _SalesOrder.[isDeleted] = 0 or _SalesOrder.[isDeleted] is null ) and ( ( 1 = 1 ) ) 
 
and ( 
  ( exist
  (
  SELECT count(*) FROM SalesOrder _SalesOrder_2 WHERE _SalesOrder_2.SalesOrderId=_SalesOrder.SalesOrderId 
[color=#0000FF]group by CONVERT(
  varchar(10),_SalesOrder_2.CreatedOn,120) HAVING count(*)>1
  ) )
  ) 
  )order by _SalesOrder.[modifiedOn] desc[/color]
【结果:】
关键字'SELECT'附近有语法错误
')'附近有语法错误


主要是and后面那一段,and前面那一段能正确执行,我们经理说可能是括号的问题

------解决方案--------------------
SQL code

and exists
  (
  SELECT count(*) FROM SalesOrder _SalesOrder_2 WHERE _SalesOrder_2.SalesOrderId=_SalesOrder.SalesOrderId  
    group by CONVERT(  varchar(10),_SalesOrder_2.CreatedOn,120) HAVING count(*)>1

  )