仅当我添加数据库名称时特定选择才起作用
我正在使用 SQL Server 2008 Express
所有的 select 语句都很好。现在我有这个:
SELECT
ORG.id, ORG.img, ORG.name, ORG.city, ORG.address,
ORG.zip, ORG.telephone, ORG.telephone2,
ORG.fax, ORG.email, ORG.vaname, ORG.vanumber,
ORG.yor_photo, ORG.commission,
Clients.id AS yor_id, Clients.prefix,
Clients.fname, Clients.lname, Clients.phone,
Clients.pelephone, Clients.email, Clients.pid,
ORG.adddate, ORG.note
FROM Org
LEFT OUTER JOIN
(select * from Clients where yor = 1) as Clients ON Clients.company = ORG.id
WHERE ORG.id=" & ORGID
它不起作用,我收到错误“无效的对象名称”
如果我在表名前面添加 DBNAME.DBO 它可以工作
问题是我不想在每个项目上更改它
为什么它不起作用吗?
更新
问题不在于数据库名称,问题在于选择语句中的AS yor_id。 如果我删除它,检索到的记录并不包含所有数据,但如果我写入它,数据已满,但 yor_id 为空
更新
没关系,我的错! id 列已损坏
I'm using SQL Server 2008 Express
All of the select statments are fine. Now I have this one:
SELECT
ORG.id, ORG.img, ORG.name, ORG.city, ORG.address,
ORG.zip, ORG.telephone, ORG.telephone2,
ORG.fax, ORG.email, ORG.vaname, ORG.vanumber,
ORG.yor_photo, ORG.commission,
Clients.id AS yor_id, Clients.prefix,
Clients.fname, Clients.lname, Clients.phone,
Clients.pelephone, Clients.email, Clients.pid,
ORG.adddate, ORG.note
FROM Org
LEFT OUTER JOIN
(select * from Clients where yor = 1) as Clients ON Clients.company = ORG.id
WHERE ORG.id=" & ORGID
It is not working, I get error "invalid object name"
If I add the DBNAME.DBO in front of the table name it works
The problem is that i don't want to change that on every project
Why is it not working?
UPDATE
the problem is not with the db name, the problem is with the AS yor_id in the select statment.
if i remove it the record retrieved is not full with all the data but if i write it the data is full but yor_id is empty
UPDATE
NEVER MIND, my bad! id column was corupted
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在该查询之前,您需要编写
以便切换到您的数据库名。
也许您正在主数据库上运行该查询,因此只需执行此操作即可:
Before that query you need to write
in order to switch to your dbname.
Probably you are running that query on master database, so just do this and should work: