简体   繁体   English

SQL Server 2008选择

[英]SQL server 2008 select in

I have this basic consult is sql, but is giving me this error in management studio: 我有这个基本的咨询是sql,但是在Management Studio中却给了我这个错误:

SELECT * 
FROM [Oficios_dev2].[dbo].[doc].[typecdocumentdet] as [C] 
where [C].[TypeCDocument] in (select [Oficios_dev2].[dbo].[doc].[TypeCDocument] as [D] 
                              where [D].[Id] = '1')

Error 错误

Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "D.Id" could not be bound.
Msg 4104, Level 16, State 1, Line 3
The multi-part identifier "Oficios_dev2.dbo.doc.TypeCDocument" could not be bound.

I have no idea why , anyone? 我不知道为什么,有人吗? Thanks 谢谢

EDIT: New query: 编辑:新查询:

SELECT *
FROM [Oficios_dev2].[dbo].[doc] as [C] where [C].[TypeCDocument]  in (select [Oficios_dev2].[dbo].[doc] from [Oficios_dev2].[dbo].[doc] as [D] where [D].[Id] = '1')

this gives me less errors still 1 这给了我更少的错误仍然1

The multi-part identifier "Oficios_dev2.dbo.doc" could not be bound.

the inner query is not formatted correctly: 内部查询的格式不正确:

you have: 你有:

(select [Oficios_dev2].[dbo].[doc].[TypeCDocument] as [D] where [D].[Id] = '1')

should by something like this: 应该是这样的:

(select TypeCDocument FROM [Oficios_dev2].[dbo].[doc] as [D] where [D].[Id] = '1')

You should test the inner query that you're using. 您应该测试所使用的内部查询。 It should be able to run independently of the full query. 它应该能够独立于完整查询运行。 In this example, the inner query does not have the correct` syntax. 在此示例中,内部查询的语法不正确。

SELECT * 
FROM [Oficios_dev2].[dbo].[typecdocumentdet] as [C] 
where [C].[TypeCDocument] in (select [TypeCDocument]
                              from [Oficios_dev2].[dbo].[doc] as [D] 
                              where [D].[Id] = '1')

Note: I'm assuming that [doc] is the name of the table you want to the inner query to run on, and the [TypeCDocument] is the column you want to select for use by the IN expression list. 注意:我假设[doc]是要在其上运行内部查询的表的名称,并且[TypeCDocument]是要选择供IN表达式列表使用的列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM