1

サブクエリを実行しているとき、すべてが期待どおりに問題なく、サブクエリの結果に基づいて列を更新するために同じクエリを使用していますが、サブクエリが意味のある複数の行を返したと表示されます..これをどのように解決すればよいですか..

begin transaction
update trn_RatingAuto                                                        
set Rate  = 0 
where rate = (
SELECT ar.Rate
FROM trn_account ta
INNER JOIN trn_risk tr  ON ta.AccountId=tr.AccountId
inner join trn_option ot on tr.riskid = ot.riskid
INNER JOIN trn_Rating ra ON ot.RatingId = ra.RatingId
INNER JOIN trn_RatingAuto ar on ra.RatingId = ar.RatingId
where  ar.Rate is null 
)
4

4 に答える 4

2

INの代わりに使用する必要があります=

update trn_RatingAuto
set Rate  = 0 
where rate IN (
  SELECT ar.Rate
  FROM trn_account ta
  INNER JOIN trn_risk tr  ON ta.AccountId=tr.AccountId
  inner join trn_option ot on tr.riskid = ot.riskid
  INNER JOIN trn_Rating ra ON ot.RatingId = ra.RatingId
  INNER JOIN trn_RatingAuto ar on ra.RatingId = ar.RatingId
  where  ar.Rate is null 
)

編集:

次の方法で更新を行うこともできます。

update ar
set Rate  = 0 
FROM trn_account ta
INNER JOIN trn_risk tr  ON ta.AccountId=tr.AccountId
inner join trn_option ot on tr.riskid = ot.riskid
INNER JOIN trn_Rating ra ON ot.RatingId = ra.RatingId
INNER JOIN trn_RatingAuto ar on ra.RatingId = ar.RatingId
where  ar.Rate is null
于 2012-10-24T17:53:04.843 に答える
0

=場所を からに変更しますinか?

begin transaction
update trn_RatingAuto                                                        
set Rate  = 0 
where rate in (
SELECT ar.Rate
FROM trn_account ta
INNER JOIN trn_risk tr  ON ta.AccountId=tr.AccountId
inner join trn_option ot on tr.riskid = ot.riskid
INNER JOIN trn_Rating ra ON ot.RatingId = ra.RatingId
INNER JOIN trn_RatingAuto ar on ra.RatingId = ar.RatingId
where  ar.Rate is null 
)
于 2012-10-24T17:52:29.663 に答える
0

複数の行を更新する場合は、クエリを「更新元」クエリに変更する必要があります...

SQL Server 2005 'update from' クエリ

お気に入り:

 update trn_RatingAuto
   set Rate  = 0  
 from trn_RatingAuto
 join (...
于 2012-10-24T17:55:44.837 に答える
0

私はこのスクリプトを SQLServer2008R2 で書きました。

UPDATE x
SET x.Rate  = 0 
FROM (
      SELECT ar.Rate
      FROM trn_account ta INNER JOIN trn_risk tr  ON ta.AccountId=tr.AccountId
                          INNER JOIN trn_option ot ON tr.riskid = ot.riskid
                          INNER JOIN trn_Rating ra ON ot.RatingId = ra.RatingId
                          INNER JOIN trn_RatingAuto ar ON ra.RatingId = ar.RatingId
      WHERE  ar.Rate is null
      ) x
于 2012-10-25T07:38:39.193 に答える