我有这样的加入:
"SELECT ADB.column1, BDB.column2 FROM ADB RIGHT JOIN BDB ON
(SELECT SUBSTRING( ADB.column1, LEN(ADB.column1) -
CHARINDEX('|',REVERSE(ADB.column1)) + 2 ,
LEN(ADB.column1) ) FROM BDB) = BDB.column2", sqlCon);
运行此代码时出现错误
System.Data.SqlClient.SqlException:'子查询返回了1个以上 值。当子查询遵循=,!=,<,<=
时,不允许这样做,> =或将子查询用作表达式时。'
如何强制子查询每行仅获取1个数据?
答案 0 :(得分:1)
我认为您的查询将如下所示
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="log"
xsi:type="File"
fileName="${basedir}/logs/log.${longdate:cached=true}.log"
layout="${message}"
archiveFileName="${basedir}/logs/archives/log.${shortdate}.{#}.log"
archiveAboveSize="5242880"
archiveEvery="Day"
archiveNumbering = "Rolling"
maxArchiveFiles="20"
/>
<target name="logconsole" xsi:type="Console" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logconsole" />
<logger name="*" minlevel="trace" writeTo="log" />
</rules>
</nlog>
您正在加入ADB和BDB,但在使用的加入条件下,请从BDB中选择没有任何意义
答案 1 :(得分:0)
似乎您确实使自己感到困惑...您不需要子选择FROM BDB
,因为您拥有所有这些ADB.column1
转换。
SELECT ADB.column1, BDB.column2
FROM ADB
RIGHT JOIN BDB
ON SUBSTRING(ADB.column1, LEN(ADB.column1) -
CHARINDEX('|',REVERSE(ADB.column1)) + 2 ,
LEN(ADB.column1)
) = BDB.column2