對於每行,插入到我在使用「For Each Row」循環中的 INSERT INTO 語句時遇到了問題。我想從“Type”列中尋找一個類別,並根據該類別選擇“COLUMN_NAME”列中的值,從而為每個類別建立一個清單。我認為我的 INSERT INTO 語句有問題。
// Get the current data table
dt = Current Data Table();
colName = "Type";
// Get the column reference
Types = Column( colName );
// Extract all values from the column
allValues = Types << Get Values;
// Get unique values (removes duplicates)
Cats = Associative Array( allValues ) << Get Keys;
// Sort the unique values (optional)
Cats = Sort List( Cats );
// Display results in the log
Show( Cats );
delCats = {"", "-"};
For( i = 1, i <= N Items( delCats ), i++,
Remove From( Cats, As List( Loc( Cats, delCats[i] ) ) )
);
show(Cats);
For For( i = 1, i <= N Items( Cats ), i++,
Spud = Char(Cats(i));
Spud = {};
For Each Row(
// Access column values directly by name
If(:Type = Char(Cats[i]), Insert Into(Spud, :COLUMN_NAME) ;
);
));
陳述。
自動化和腳本編寫回覆:對於每一行,插入到(如果我理解正確的話)你不需要使用 For Each Row。只需使用 For Each 循環,並結合 << Get Rows Where 語句和資料表下標,即可將值新增至清單。
回覆:對於每一行,插入到提供的程式碼無法運行,而且由於缺少適當的空格,難以閱讀。我猜測它是人工智慧生成的,因為它使用了一些奇怪的JSL技術(例如,即使關聯數組的鍵已經排序,它仍然對其進行排序等等)。
僅根據提供的程式碼(和問題),我不太確定你的目標是什麼。但是,你可能在每次循環中都替換了 Spud 列表,這導致了問題。
回覆:對於每一行,插入到連續的分配
Spud = Char(Cats(i));
Spud = {};
它們會用第二個元素覆蓋第一個元素。它們也位於外層循環內,這就是為什麼@jthi認為列表是被重新創建而不是擴展的原因。
添加一個
show( row(), spud, ...etc... );
在日誌中多處取得中間結果的語句也可能有所幫助。或者
write( "\!n x=" || char(x) || " y=" || char(y) );
如果你想格式化它的話。或者
write( Eval Insert("\!n x=^x^ y=^y^) );
這樣可能比較容易閱讀。
JSL 編輯器有一個重新格式化命令,可以幫助解決循環縮排在視覺上錯位的問題。