如何解决Msg 512,Level 16,State 1,Line 1 Subquery返回的值超过1

时间:2017-01-11 16:44:06

标签: sql sql-server

Select 
    c.name, c.number, f.Telephone3 As 'Phone Number', 
    (Select Value 
     from UserDefinedFieldLinks 
     where UserDefinedFieldID = 134) AS 'Referal Name',
    (Select Value 
     from UserDefinedFieldLinks 
     where UserDefinedFieldID = 135) AS 'Referal Acc No.', 
    (Select Value 
     from UserDefinedFieldLinks 
     where UserDefinedFieldID = 137) AS 'Referal Phone No.', 
    udl.value as Answer 
From 
    Customer C
Join 
    UserDefinedFieldLinks udl on udl.CustomerID = C.CustomerID
Join 
    UserDefinedFields d on udl.UserDefinedFieldID = d.UserDefinedFieldID
Join 
    UserDefinedFieldGroup e on d.UserDefinedFieldGroupID = e.UserDefinedFieldGroupID
Join 
    person f on C.CustomerID = f.PersonID
Where 
    e.UserDefinedFieldGroupID = 10

1 个答案:

答案 0 :(得分:0)

下面之一是返回多个值,这意味着UserDefinedFieldID不是唯一的:

(Select Max(Value) from UserDefinedFieldLinks where UserDefinedFieldID = 135)

如果每个UserDefinedFieldID(未规范化)的值重复,那么您可以使用:

:not