2016-09-13 93 views
2

我試圖更新所有creditCounts除了第一個(最低)帳號,但是我不斷收到此錯誤:SQL - 子查詢不引入EXISTS

Msg 116, Level 16, State 1, Line 8
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

下面是該查詢:

update Recog 
set livesCount = 0 
where RECID in (select 
        r.empNumber, r.acctNbr, r.creditCount, r.groupAcctNumber, r.groupType 
       from 
        Recog r 
       where 
        creditCount > 0 
        and policyNbr in 
         (
          (Select acctNbr from Recog) 
          except 
          (Select MIN(acctNbr) 
          from Recog 
          Group By groupAcctNumber, groupType) 
          ) 
         ) 

我該如何解決?

+2

你在說'Where RECID in ...',然後給它5個字段。你只能在'in'中選擇一個。 – Santi

回答

6

由於錯誤狀態,您選擇多列的子查詢,它纔有意義,選擇一個......

update Recog 
    set livesCount = 0 
    where RECID in (
    select r.RECID 
    from Recog r 
      where creditCount > 0 and 
      policyNbr in ((Select acctNbr from Recog) 
      except (Select MIN(acctNbr) from Recog Group By groupAcctNumber,groupType))) 

要回家駕駛它,想象你的聲明將是什麼,如果你喜歡取代列數據代替你的子查詢...

update Recog 
    set livesCount = 0 
    where RECID in (1, 'Account 123', 12, 'Group 123', 'Type X') -- Makes no sense