(SELECT
Dbo.DecryptString(LastName) + '', '' +
Dbo.DecryptString(FirstName) as PatientName
FROM Persons.Informations
WHERE PersonId = (SELECT PersonId
FROM Patients.Informations
WHERE PatientId = TST.PatientId))
From Transactions.SessionTransaction TST ON TST.PaymentId = TP.PaymentId
你能告诉我这个查询有什么问题吗?
为什么会出错:
“当选择列表中只能指定一个表达式 EXISTS没有引入子查询。“
答案 0 :(得分:0)
您必须使用IN
谓词而不是=
,以防您必须比较WHERE
子句返回的多个值,因此在您的查询中,而不是
WHERE PersonId = (SELECT PersonId
FROM Patients.Informations
WHERE PatientId = TST.PatientId)
请改为尝试:
...
WHERE PersonId IN (SELECT PersonId
FROM Patients.Informations
WHERE PatientId = TST.PatientId)
...
但是,您可以直接JOIN
表格,而不是此谓词IN
,如下所示:
SELECT
...
FROM Persons.Informations i
INNER JOIN Transactions.SessionTransaction TST ON i.PersonId = TST.PersonId
INNER JOIN ... TP ON TST.PaymentId = TP.PaymentId
答案 1 :(得分:0)
如果您尝试将姓氏和名字组合在一起,用逗号分隔,则引号太多:
(SELECT
Dbo.DecryptString(LastName) + ', ' +
Dbo.DecryptString(FirstName) as PatientName
FROM Persons.Informations
WHERE PersonId = (SELECT PersonId
FROM Patients.Informations
WHERE PatientId = TST.PatientId))
From Transactions.SessionTransaction TST ON TST.PaymentId = TP.PaymentId
您的原始查询正在尝试返回两列 - 附加了空字符串的姓氏(实际上是无操作),并且第一个名称前面带有空字符串(同样,实际上是无操作) )。