0

这是我的查询

SELECT cont.FILTER_VALUE as filter,
    o.[OBJECT_ID] as Id, o.[OBJECT_NAME] as Name, o.DESCRIPTION as Description, o.CREATED as Created,
     o.MODIFIED as Modified,  u.[LOGIN] as LastModifiedByLogin, o.[OBJECT_NAME] as ObjectName, t.[TEMPLATE_NAME] as TemplateName--,p.[PAGE_NAME] as PageName 
    FROM 
     [OBJECT] AS o
     LEFT OUTER JOIN [CONTAINER] as cont 
     on cont.[OBJECT_ID] = o.[OBJECT_ID]

     LEFT JOIN [OBJECT_VALUES] AS ov ON
     ov.[OBJECT_ID] = o.[OBJECT_ID]
     LEFT JOIN [PAGE] AS p ON o.[PAGE_ID] = p.[PAGE_ID] 
     INNER JOIN [USERS] as u on u.[USER_ID] = o.LAST_MODIFIED_BY INNER JOIN [PAGE_TEMPLATE] as t 
     on o.[PAGE_TEMPLATE_ID] = t.[PAGE_TEMPLATE_ID] INNER JOIN [site] as s on t.SITE_ID = s.SITE_ID 
     WHERE
     s.SITE_ID = '34' --AND сont.[FILTER_VALUE] is null--like '%fff%'

效果很好,直到我删除评论。

这是一团糟的连接,但它仍然有意义。我inner join与其他几个主表,并且left join可选,所以,我有一个列,其中包含cont.FILTER_VALUE as filter,它在某些记录中为空,我可以得到它,但我不能按这个字段过滤。

我明白了The multi-part identifier "сont.FILTER_VALUE" could not be bound.

我浏览了类似的主题,但没有找到有用的信息。我不使用任何旧的 SQL 方言:在任何地方我都使用INNER/LEFT连接,尝试过group byorder by尝试重新排序连接 - 没有任何帮助。我想我只是不明白关于连接的重要内容,请你告诉我。

谢谢。

4

3 回答 3

0

我不知道您为什么会收到错误消息,但请尝试以防万一,同时我们等待更好的答案:

SELECT FILTER_VALUE as filter
   , o.[OBJECT_ID] as Id
   , o.[OBJECT_NAME] as Name
   , o.DESCRIPTION as Description
   , o.CREATED as Created
   , o.MODIFIED as Modified
   , u.[LOGIN] as LastModifiedByLogin
   , o.[OBJECT_NAME] as ObjectName
   , t.[TEMPLATE_NAME] as TemplateName
FROM [OBJECT] AS o
INNER JOIN [USERS] as u 
  ON u.[USER_ID] = o.LAST_MODIFIED_BY 
INNER JOIN [PAGE_TEMPLATE] as t 
  ON o.[PAGE_TEMPLATE_ID] = t.[PAGE_TEMPLATE_ID] 
INNER JOIN [site] as s 
  ON t.SITE_ID = s.SITE_ID 
LEFT JOIN [CONTAINER] as cont 
  ON cont.[OBJECT_ID] = o.[OBJECT_ID]
LEFT JOIN [OBJECT_VALUES] AS ov 
  ON ov.[OBJECT_ID] = o.[OBJECT_ID]
LEFT JOIN [PAGE] AS p 
  ON o.[PAGE_ID] = p.[PAGE_ID] 
WHERE s.SITE_ID = '34' AND FILTER_VALUE IS NULL
于 2013-06-25T22:56:03.843 回答
0

好吧,我用CTE解决了这个问题,但我仍然想知道,为什么没有cte我会出现问题。

这种方式效果很好

with query_CTE
AS
(
SELECT 
ROW_NUMBER() OVER (ORDER BY o.[OBJECT_ID] asc) as rowNum,
o.[OBJECT_ID] as Id, o.[OBJECT_NAME] as Name, o.DESCRIPTION as Description, o.CREATED as Created,
 o.MODIFIED as Modified,  u.[LOGIN] as LastModifiedByLogin, o.[OBJECT_NAME] as ObjectName, t.[TEMPLATE_NAME] as TemplateName,p.[PAGE_NAME] as PageName,

 s.SITE_ID, t.PAGE_TEMPLATE_ID, p.PAGE_ID, ov.VARIABLE_NAME, ov.VARIABLE_VALUE, cont.FILTER_VALUE, cont.DYNAMIC_CONTENT_VARIABLE, cont.SELECT_START,
 cont.SELECT_TOTAL  
FROM [OBJECT] AS o
INNER JOIN [USERS] as u 
  ON u.[USER_ID] = o.LAST_MODIFIED_BY 
INNER JOIN [PAGE_TEMPLATE] as t 
  ON o.[PAGE_TEMPLATE_ID] = t.[PAGE_TEMPLATE_ID] 
INNER JOIN [site] as s 
  ON t.SITE_ID = s.SITE_ID 
LEFT JOIN [CONTAINER] as cont 
  ON cont.[OBJECT_ID] = o.[OBJECT_ID]
LEFT JOIN [OBJECT_VALUES] AS ov 
  ON ov.[OBJECT_ID] = o.[OBJECT_ID]
LEFT JOIN [PAGE] AS p 
  ON o.[PAGE_ID] = p.[PAGE_ID] 

)

从 query_CTE 中选择 rowNum、Id、Name、[Description]、Created、Modified、LastModifiedByLogin、ObjectName、TemplateName、PageName

于 2013-06-26T09:37:27.020 回答
0

如果你这样写:
s.SITE_ID = '34' AND сont.[FILTER_VALUE] is null like '%fff%'
它只是错误的语法。您缺少 LIKE 函数的一列(查询假设在哪一列中查找模式?)。如果你不是那样写的,请发布你写的内容

于 2013-06-25T22:45:59.393 回答