Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
suzi0000
Contributor
Contributor

ロードするデータの列名について

以下のような2種類のcsvファイルをロードし、Aの列名をBのデータで設定したいと思っています。

良い方法があれば教えてください。

A.csv

--------------------

1     東京

2     神奈川

3     千葉

B.csv

-------------------

ID

都道府県

QV上でのテーブルイメージ

列名     ID     都道府県

-------------------------------------------

        1      東京

        2      神奈川

        3      千葉

Labels (2)
1 Solution

Accepted Solutions
hka
Employee
Employee

下記でできます。

Bの件数が変更される場合も考慮してあります。

Aの項目数がBの件数と同じことが前提です。

---------------------------------

LOAD @1 as Col
FROM
B.csv
(txt, codepage is 932, no labels, delimiter is '\t', msq);

LET vScript = '';
LET vRow = NoOfRows('B');

for i = 1 to $(vRow)
if $(i) = '1' then
  LET vScript = '@$(i) as ' & Peek('Col',$(i)-1,'B') & ', ';
ELSEIF $(i)= $(vRow) then
  LET vScript = '$(vScript)@$(i) as ' & Peek('Col',$(i)-1,'B') ;
ELSE
  LET vScript = '$(vScript)' & Peek('Col',$(i)-1,'B')& ', ' ;
endif
next i;


LOAD $(vScript)
FROM
A.csv
(txt, codepage is 932, no labels, delimiter is ',', msq);


DROP Table B;

---------------------------------

View solution in original post

2 Replies
hka
Employee
Employee

下記でできます。

Bの件数が変更される場合も考慮してあります。

Aの項目数がBの件数と同じことが前提です。

---------------------------------

LOAD @1 as Col
FROM
B.csv
(txt, codepage is 932, no labels, delimiter is '\t', msq);

LET vScript = '';
LET vRow = NoOfRows('B');

for i = 1 to $(vRow)
if $(i) = '1' then
  LET vScript = '@$(i) as ' & Peek('Col',$(i)-1,'B') & ', ';
ELSEIF $(i)= $(vRow) then
  LET vScript = '$(vScript)@$(i) as ' & Peek('Col',$(i)-1,'B') ;
ELSE
  LET vScript = '$(vScript)' & Peek('Col',$(i)-1,'B')& ', ' ;
endif
next i;


LOAD $(vScript)
FROM
A.csv
(txt, codepage is 932, no labels, delimiter is ',', msq);


DROP Table B;

---------------------------------

suzi0000
Contributor
Contributor
Author

早速の返信ありがとうございます。

教えていただいた方法で確認してみようと思います。

ありがとうございました。