Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQL server 2008在中选择_C#_Sql_Sql Server 2008 R2 - Fatal编程技术网

C# SQL server 2008在中选择

C# SQL server 2008在中选择,c#,sql,sql-server-2008-r2,C#,Sql,Sql Server 2008 R2,我有一个基本的查询是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'

我有一个基本的查询是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')
错误

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

编辑:新查询:

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.

内部查询的格式不正确:

你有:

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

内部查询的格式不正确:

你有:

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

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

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]
是要在
表达式列表中选择供
使用的列。

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

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]
是要在
表达式列表中选择供
使用的列。

内部选择忽略了一个字段列表和一个
来自
。Oficios\u dev2
是远程服务器吗?如果是,则需要将其添加为链接服务器。选中
select*from sys.servers
,查看是否已将其添加为链接服务器。内部选择将错过一个字段列表和一个
from
。Oficios_dev2
是否为远程服务器?如果是,则需要将其添加为链接服务器。检查
select*from sys.servers
以查看它是否已添加为链接服务器。我现在更改为此,它给出了以下信息:在sys.servers中找不到服务器'Oficios_dev2'。验证是否指定了正确的服务器名称。如有必要,执行存储过程sp_addlinkedserver将服务器添加到sys.servers。建议的文本已由@Gordon更正。。。您是在他的编辑之前还是之后尝试的?如果Oficios_dev2的
是远程服务器,则需要将其添加为链接服务器。选中“从sys.servers中选择*”
,查看服务器是否设置为远程服务器,以及名称拼写是否正确。如果未将其设置为远程服务器,则需要将其与sp_addlinkedserver存储过程一起添加。是的,它不是本地的。(:我现在更改为此,但它给了我以下信息:在sys.servers中找不到服务器'Oficios_dev2'。请验证是否指定了正确的服务器名称。如有必要,请执行存储过程sp_addlinkedserver将服务器添加到sys.servers。建议的文本已由@Gordon更正…您是在编辑之前还是之后尝试过它?If
Oficios_dev2
是远程服务器,则需要将其添加为链接服务器。请检查
从sys.servers
中选择*以查看服务器是否设置为远程服务器以及名称拼写是否正确。如果未将其设置为远程服务器,则需要使用sp_addlinkedserver存储过程将其添加。是的,它不是本地服务器。(: