简体   繁体   English

sql server error =当子查询跟随=,!=,<,<=,>,> =或将子查询用作表达式时,不允许这样做

[英]sql server error = This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression

I have a problem with my code. 我的代码有问题。

I use this code for create a view on sql server : 我使用此代码在sql服务器上创建视图:

SELECT
(SELECT FirstNameD + ' ' + LastNameD AS Expr1
 FROM   dbo.UsersDatas) AS UsersFullName,
 PhoneNumberD, EmailAddressD, UserNameD
FROM dbo.UsersDatas AS UsersDatas_1   

and use this view in my c# application. 并在我的C#应用​​程序中使用此视图。

after I set two rows with my c# app, I get this error from Visual Studio : 在使用c#应用程序设置两行之后,我从Visual Studio中收到以下错误消息:

System.Data.Entity.Core.EntityCommandExecutionException: 'An error occurred while reading from the store provider's data reader. System.Data.Entity.Core.EntityCommandExecutionException:'从商店提供者的数据读取器读取时发生错误。 See the inner exception for details.' 有关详细信息,请参见内部异常。

my c# code is: 我的C#代码是:

private void SetDataGridViewDatasMethod()
{
    var Query = from MU in DataBaseDataD.VW_UsersDatasView
    select MU;
    var UsersDataD = Query.ToList();
    UsersInfoDataGridView.ItemsSource = UsersDataD;
}

and I search a lot about it on the internet but I can't find any solution could you help me fix this problem please? 并且我在互联网上搜索了很多相关信息,但是找不到任何解决方案,您能帮我解决这个问题吗?

If you want fullname you can do like this, no need of inner query 如果要全名,可以这样,不需要内部查询

 SELECT
FirstNameD + ' ' + LastNameD  AS UsersFullName,
 PhoneNumberD, EmailAddressD, UserNameD
FROM dbo.UsersDatas 

As Shantanu says - no need for the inner query. 正如Shantanu所说-不需要内部查询。 And rather than using the "+" operator you might want to use CONCAT 而且,您可能不希望使用“ +”运算符来使用CONCAT

SELECT CONCAT(FirstNameD, ' ', LastNameD)  AS UsersFullName,
 PhoneNumberD, EmailAddressD, UserNameD
FROM dbo.UsersDatas 

Or, if you're using SQL Server 2017 you could also use CONCAT_WS 或者,如果您使用的是SQL Server 2017,则也可以使用CONCAT_WS

SELECT CONCAT_WS(' ', FirstNameD, LastNameD)  AS UsersFullName,
 PhoneNumberD, EmailAddressD, UserNameD
FROM dbo.UsersDatas

The key difference between + and CONCAT is how they behave when one of the inputs is NULL. +和CONCAT之间的主要区别在于,当输入之一为NULL时,它们的行为方式。

暂无
暂无

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

相关问题 SQL错误:当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或将子查询用作表达式时,不允许这样做 - SQL ERROR: This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression SQL错误-子查询后跟=,!=,&lt;,&lt;=,&gt;,&gt; =或将子查询用作表达式时,不允许这样做 - Error in SQL - This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或用作表达式时,不允许使用 - Not permitted when the subquery follows =, !=, <, <= , >, >= or when used as an expression SQL Server子查询返回了多个值。 当子查询跟随(字符)或子查询用作表达式时,不允许这样做 - SQL Server Subquery returned more than 1 value. This is not permitted when the subquery follows (chars) or when the subquery is used as an expression 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或将子查询用作表达式时,不允许这样做 - This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression 如何解决错误:“子查询返回了多个值”。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =或用作表达式时,不允许使用 - How to fix error: “Subquery returned more than 1 value”. Not permitted when subquery follows =, !=, <, <= , >, >= or used as an expression 子查询返回超过 1 个值。 当子查询跟随......或当子查询用作表达式时,这是不允许的 - Subquery returned more than 1 value. This is not permitted when the subquery follows … or when the subquery is used as an expression 子查询返回的值超过1。 当子查询遵循&gt; =或将子查询用作表达式时,不允许这样做 - Subquery returned more than 1 value. This is not permitted when the subquery follows>= or when the subquery is used as an expression 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =时,不允许这样做 - This is not permitted when the subquery follows =, !=, <, <= , >, >= 获取错误SQL Server子查询返回了多个值。 当子查询遵循=,!=,&lt;,&lt;=,&gt;,&gt; =时,不允许这样做 - Get Error SQL Server Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >=
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM