没有为'eu'

时间:2016-08-10 22:41:26

标签: sql sql-server excel sql-server-2012 excel-2007

尝试在excel 2007中将此sql设置为数据连接:

select sv.accountid, sv.companyName, sv.siteid, sv.siteName + '('+sv.siteCity + '-' + sv.siteState + ')' as siteNameWithLocation,
datefromparts(datepart(yyyy,r.logdate),datepart(mm,r.logdate),1) as monthDate, 
sum('controllerEstKGal') / 1000 as siteEstimatedTotalKgals
from RuntimeDay r WITH (READUNCOMMITTED) 
join controller c on c.id = r.controllerid
join siteView sv on sv.siteid = c.siteid
join (
SELECT r.controllerid, r.logdate, SUM((ISNULL(r.RuntimeSec, 0)/60.0) * ISNULL(s.EsrfGpm, 0)) as 'controllerEstKGal'
  FROM RuntimeDay r WITH (READUNCOMMITTED)
  JOIN CdcView c    WITH (READUNCOMMITTED) ON r.ControllerId = c.ControllerId
  JOIN StationFlowConfig s WITH (READUNCOMMITTED) 
       ON r.ControllerId = s.ControllerId AND r.StationNumber = s.StationId
 WHERE c.siteid in (8547, 8299, 8556, 8541, 8292, 8600, 8551, 5487, 8555, 8216, 8342, 8557, 8287, 8542, 8221, 5509, 8218, 8543, 8336, 8343)
   AND logDate between '2016-01-01' and '2016-12-31'
   AND r.RuntimeSec > 0
   AND s.EsrfGpm > 0
    group by r.controllerid, r.logdate
) eu on eu.controllerid = r.controllerid and eu.logDate = r.logdate
where sv.siteid in (8547, 8299, 8556, 8541, 8292, 8600, 8551, 5487, 8555, 8216, 8342, 8557, 8287, 8542, 8221, 5509, 8218, 8543, 8336, 8343) and r.logDate between '2016-01-01' and '2016-12-31'
group by sv.accountid, sv.companyName, sv.siteid, sv.siteName + '('+sv.siteCity + '-' + sv.siteState + ')',
datefromparts(datepart(yyyy,r.logdate),datepart(mm,r.logdate),1)

我从Microsoft Query中收到以下错误消息:

  

没有为'eu'的第3列指定列名。

     

无法准备声明。

我认为“第3栏”指的是这个具体部分:

SUM((ISNULL(r.RuntimeSec, 0)/60.0) * ISNULL(s.EsrfGpm, 0)) as 'controllerEstKGal'

我之前发现过这个问题的案例,但回复说要将第3列的名称放在引号中。然而(正如你所看到的)我已经做到了,我仍然会收到这个错误。

帮我StackExchange,你是我唯一的希望! (谢谢!)

编辑:为了澄清,我在controllerEstKgal周围有和没有单/双引号的错误。反引号会导致以下错误消息:

  

'''附近的语法不正确。

     

关键字'with'附近的语法不正确。如果此语句是公用表表达式,xmlnamespaces子句或更改跟踪上下文子句,则必须以分号结束前一个语句。

     

无法准备声明。

0 个答案:

没有答案