![](/img/trans.png)
[英]SQL ERROR: This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression
[英]sql server error = This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression
我的代碼有問題。
我使用此代碼在sql服務器上創建視圖:
SELECT
(SELECT FirstNameD + ' ' + LastNameD AS Expr1
FROM dbo.UsersDatas) AS UsersFullName,
PhoneNumberD, EmailAddressD, UserNameD
FROM dbo.UsersDatas AS UsersDatas_1
並在我的C#應用程序中使用此視圖。
在使用c#應用程序設置兩行之后,我從Visual Studio中收到以下錯誤消息:
System.Data.Entity.Core.EntityCommandExecutionException:'從商店提供者的數據讀取器讀取時發生錯誤。 有關詳細信息,請參見內部異常。
我的C#代碼是:
private void SetDataGridViewDatasMethod()
{
var Query = from MU in DataBaseDataD.VW_UsersDatasView
select MU;
var UsersDataD = Query.ToList();
UsersInfoDataGridView.ItemsSource = UsersDataD;
}
並且我在互聯網上搜索了很多相關信息,但是找不到任何解決方案,您能幫我解決這個問題嗎?
如果要全名,可以這樣,不需要內部查詢
SELECT
FirstNameD + ' ' + LastNameD AS UsersFullName,
PhoneNumberD, EmailAddressD, UserNameD
FROM dbo.UsersDatas
正如Shantanu所說-不需要內部查詢。 而且,您可能不希望使用“ +”運算符來使用CONCAT
SELECT CONCAT(FirstNameD, ' ', LastNameD) AS UsersFullName,
PhoneNumberD, EmailAddressD, UserNameD
FROM dbo.UsersDatas
或者,如果您使用的是SQL Server 2017,則也可以使用CONCAT_WS
SELECT CONCAT_WS(' ', FirstNameD, LastNameD) AS UsersFullName,
PhoneNumberD, EmailAddressD, UserNameD
FROM dbo.UsersDatas
+和CONCAT之間的主要區別在於,當輸入之一為NULL時,它們的行為方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.