1

我有这个基本咨询是 sql,但在管理工作室中给了我这个错误:

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')

错误

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.

我不知道为什么,有人吗?谢谢

编辑:新查询:

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')

这给了我更少的错误仍然 1

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

2 回答 2

4

内部查询格式不正确:

你有:

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

应该是这样的:

(select TypeCDocument FROM [Oficios_dev2].[dbo].[doc] as [D] where [D].[Id] = '1')
于 2013-08-14T16:46:51.230 回答
1

您应该测试您正在使用的内部查询。它应该能够独立于完整查询运行。在此示例中,内部查询没有正确的语法。

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')

注意:我假设这[doc]是您要运行内部查询的表的名称,并且[TypeCDocument]是您要选择供IN表达式列表使用的列。

于 2013-08-14T16:59:32.247 回答