SQL Server データを結合するために多くのオプションを試しましたが、一部は機能しますが、データが正しくありません。
ユーザー、統計、および結果のテーブルがあります。最初の 2 つのテーブルからデータを取得して結合したところ、情報は問題ありません。
create table #statsTable(
s_fullname char(45), <--Here
s_dialdate smalldatetime,
s_campaign char(3),
s_calls int,
s_holdtime int,
s_talktime int,
s_wrapuptime int ,
s_dialtime int ,
s_pitches int ,
s_agent char(3) , <-- to here, insert fine
s_samount decimal(20,2), <--Here
s_damount decimal(10,2) ,
s_upamount numeric (10,0),
s_mdamount decimal (12,2)) <--to here, uses a separate query, not so much
結合などを使用してみましたが、何も機能しません。最後の 4 つの値が組み合わされているように見えますが、現在は正しくなっています。以下は、上記の表の最初の部分を挿入します。
INSERT INTO #statsTable (s_fullname, s_agent, s_calls,
s_holdtime, s_talktime, s_wrapuptime, s_pitches, s_dialtime, s_campaign,
s_dialdate)
SELECT
agent.name, agent.code, calls, holdtime,
talktime, wrapuptime, pitches, dialtime, campaign,
dialdate
FROM stats, agent
WHERE
agent.code LIKE stats.agent
AND dialdate = '02-27-2013'
次の部分で問題が発生します。参加しようとしても、挿入または更新クエリを使用しようとしても、最後の 4 つのフィールドがごちゃごちゃになります。
データを取得している 3 つのテーブルは次のようになります。
agent
name (full name)
code (3 char ID)
stats
dialdate
agent (3 char ID)
campaign (3 char ID)
calls (number of calls)
holdtime
talktime
wrapuptime
dialtime
pitches
results
lcdate (date last call was made)
campaginid (3 char ID)
sale (overall sale amount)
donation (donation amount)
up_sale (up-sale amount)
md_amount (not sure its purpose, but a decimal none the less)
これらの各テーブルには明らかにより多くのデータがありますが、これは最終的な出力に関連する唯一の関連データです。
前もって感謝します