无效的对象名称 - 尝试了一些事情
Posted
技术标签:
【中文标题】无效的对象名称 - 尝试了一些事情【英文标题】:Invalid Object Name - Tried a few things 【发布时间】:2020-02-21 15:20:21 【问题描述】:我有以下疑问:
SELECT
customer_id,
SUM(extended_amount) AS total_spent,
COUNT(DISTINCT(client_web_order_number)) AS #_of_orders,
MAX(oms_order_date) AS last_purchase_date,
DATEDIFF(day, last_purchase_date, CAST(GETDATE() AS DATE)) AS days_since_last_purchase,
MIN(oms_order_date) AS registration_date,
DATEDIFF(day, registration_date, CAST(GETDATE() AS DATE)) AS days_active,
CASE
WHEN DATEDIFF(day, last_purchase_date, CAST(GETDATE() AS DATE)) = DATEDIFF(day, registration_date, CAST(GETDATE() AS DATE))
THEN 'One-time purchase'
ELSE ''
END AS notes
FROM
[us_raw].[l_dmw_order_report]
WHERE
quantity_ordered > 0
AND customer_id IS NOT NULL
AND customer_id != ('')
AND customer_id LIKE 'US%'
AND oms_order_date IS NOT NULL
AND UPPER(line_status) NOT IN ('','RETURN', 'CANCELLED')
AND UPPER(item_description_1) NOT IN ('','FREIGHT', 'RETURN LABEL FEE', 'VISIBLE STITCH')
AND (quantity_ordered * unit_price_amount) > 0
AND extended_amount < 1000 --NO BULK ORDERS
AND oms_order_date BETWEEN '2018-01-01' AND GETDATE()
AND SUBSTRING(upc,1,6) IN (SELECT item_code FROM item_master_zs WHERE new_division BETWEEN '11' AND '39')
GROUP BY
customer_id
--HAVING
-- SUM(extended_amount) BETWEEN 1 AND 50
它一直告诉我“无效的对象名称”。 该表存在。 我检查了下拉菜单以确保连接了正确的数据库。 我刷新了 Intellisense 缓存。
不知道还能做什么......
【问题讨论】:
是运行时错误吗? 什么说无效的对象名称? 更新帖子。它在结果中。 您在错误的数据库中。看看哪里写着“主人”。 总是在查询开始时使用我认为您正在寻找链接服务器对象名称,如果是,那么您需要调用它:
<linked-server-name>.<database-name>.<schema>.<object-name>
所以,之后SELECT
声明会看起来:
SELECT <alias>.*
FROM <linked-server-name>.<database-name>.<schema>.<object-name> AS <alias>
【讨论】:
以上是关于无效的对象名称 - 尝试了一些事情的主要内容,如果未能解决你的问题,请参考以下文章
SqlAdapter 无法识别我的表:异常“无效的对象名称”
ExecuteSqlCommand 返回“无效的对象名称”错误