-1

下の別のデータからかさばるデータを追加したい。しかし、それはできません。エラーが返されます。しかし、地域は同じです。

declare @hrmtable1 table(musterino int, ekno smallint)

insert into @hrmtable1 (musterino , ekno)
    select distinct musterino, ekno
    from hareketmuhasebe (nolock) 
    where islemtarihi >= '20120101'
      and isnull(musterino, 0) <> 0 
      and isnull(musterino, 0) > 9000000 
      and isnull(ekno,0) <> 0 

insert into table1(A,B,C,D,E,. . . . .N) 
   SELECT DISTINCT 
      case when ((select count(*) from table1 where musterino=e.musterino) > 0)
           then (select top 1 *
                 from dbo.table1 
                 where musterino = e.musterino  
                 order by ekno desc)
           else 
                (select 100, e.musterino, e.ekno, 0, K, L, M)
                 from @hrmtable1 e )
      end

エラー:

メッセージ 120、レベル 15、状態 1、行 10
INSERT ステートメントの選択リストには、挿入リストよりも少ない項目が含まれています。
SELECT 値の数は、INSERT 列の数と一致する必要があります。

4

4 に答える 4

0

エラーで述べたように、挿入の列の数は、提供している値の数と一致しません

insert into @hrmtable1 (musterino , ekno)
select distinct musterino,ekno
from hareketmuhasebe (nolock) 
where islemtarihi >= '20120101'
and isnull(musterino,0) <> 0 and isnull(musterino,0) < 9000000 and isnull(ekno,0) <> 0 
于 2013-02-20T12:02:59.860 に答える
0

これを試して:

insert into @hrmtable1 (musterino , ekno)
select distinct musterino,ekno
from hareketmuhasebe (nolock) 
where islemtarihi >= '20120101'
and isnull(musterino,0) <> 0 and isnull(musterino,0) < 9000000 and isnull(ekno,0) <> 0

挿入に2列、選択句に5列があり、これがエラーの原因です。

于 2013-02-20T12:03:19.720 に答える
0

INSERTステートメントの選択リストには、挿入リストよりも少ない項目が含まれています。SELECT値の数は、INSERT列の数と一致する必要があります。

エラー自体は、あなたが間違っていることを物語っています。挿入ステートメントの列は、選択ステートメントよりも少なくなります。

MSDNから

サブクエリの選択リストは、INSERTステートメントの列リストと一致する必要があります。列リストが指定されていない場合、選択リストは、挿入されるテーブルまたはビューの列と一致する必要があります。

Inertintoについてもっと読む

于 2013-02-20T12:03:53.253 に答える
0

編集:質問を編集したので、答えは同じままです。Select ステートメントの列数が、コードの 2 番目の部分にある挿入ステートメントの列と一致しません。

最初のステートメントでは2列を指定しており、select5では列があり、それらは一致する必要があり、それがエラーが正確に伝えていることです。

insert into @hrmtable1 (musterino , ekno)
                         ^^^^^^^    ^^^^
select distinct musterino,ekno,defterid,dovizcinsi, subekodu
                ^^^^^^^    ^^^   ^^^^     ^^^^^      ^^^^^

ステートメントから、insertステートメントの最後の 3 つの列は必要ないようですSelect

于 2013-02-20T12:01:17.763 に答える